lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Dear all,

is there a C in Lua distribution function that does this?

static void luasandbox_load_lua_library( lua_State * L, const char * path, const char * global ) {

    void * library;
    library = dlopen( path, RTLD_LAZY );
    if ( library ) {
        char * library_loader_name = emalloc( 9 + strlen( global ) );
        strcpy( library_loader_name, "luaopen_" );
        strcat( library_loader_name, global );
        void * library_loader;
        library_loader = dlsym( library, library_loader_name );
        lua_pushcfunction( L, library_loader );
        lua_call( L, 0, 1 );
        lua_setglobal( L, global );
    }
}


Alexander Mashin