0
|
1 #include "lua.h"
|
|
2 #include "lauxlib.h"
|
|
3 #include "dynload.h"
|
|
4
|
|
5 int lua_dlLoadLibrary(lua_State *L)
|
|
6 {
|
|
7 const char* libpath;
|
|
8 if ( lua_isnoneornil(L, 1) )
|
|
9 libpath = NULL;
|
|
10 else
|
|
11 libpath = lua_tostring(L, 1);
|
|
12 DLLib* pLib;
|
|
13 pLib = dlLoadLibrary(libpath);
|
|
14 if (pLib == NULL) return 0;
|
|
15 lua_pushlightuserdata(L, pLib);
|
|
16 return 1;
|
|
17 }
|
|
18
|
|
19 int lua_dlFreeLibrary(lua_State *L)
|
|
20 {
|
|
21 DLLib* pLib = (DLLib*) lua_touserdata(L, 1);
|
|
22 dlFreeLibrary(pLib);
|
|
23 return 0;
|
|
24 }
|
|
25
|
|
26 int lua_dlFindSymbol(lua_State *L)
|
|
27 {
|
|
28 DLLib* pLib = (void*) lua_touserdata(L, 1);
|
|
29 const char* pSymbolName = (const char*) lua_tostring(L, 2);
|
|
30 void* addr = dlFindSymbol(pLib, pSymbolName);
|
|
31 if (addr == NULL) return 0;
|
|
32 lua_pushlightuserdata(L, addr);
|
|
33 return 1;
|
|
34 }
|
|
35
|
|
36 static const struct luaL_Reg luareg_dynload[] =
|
|
37 {
|
|
38 { "dlLoadLibrary", lua_dlLoadLibrary },
|
|
39 { "dlFreeLibrary", lua_dlFreeLibrary },
|
|
40 { "dlFindSymbol", lua_dlFindSymbol },
|
|
41 { NULL, NULL }
|
|
42 };
|
|
43
|
|
44 // LUALIB_API
|
|
45 int luaopen_ldynload(lua_State *L)
|
|
46 {
|
|
47 lua_createtable(L, 0, 0);
|
|
48 luaL_register(L, NULL, luareg_dynload);
|
|
49 return 1;
|
|
50 }
|
|
51
|