[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Load .so library dynamically from C
- From: "Александр Машин" <traditio.ru@...>
- Date: Mon, 14 Sep 2020 14:09:47 +0700
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