[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: How should I set up C + Lua modules
- From: "Henderson, Michael D" <michael.d.henderson@...>
- Date: Thu, 17 Feb 2011 14:48:11 -0700
On Thursday, February 10, 2011 2:55 PM, Peter Odding wrote:
Sent:
>
> local apr = require 'apr.core'
> -- .. and the script ends with ..
> return apr
>
> The binary module is called "core.so" ("core.dll" on Windows) and is
> located in a subdirectory "apr" in one of the directories in Lua's
> binary module search path. The loader function in the binary module [3]
> is called "luaopen_apr_core".
Thanks, that got me headed in the right direction. I do have a problem with the libraries, though.
I now have a lib/aes/core.so file that contains
luaopen_aes_core(lua_State *L)
That function calls luaL_register to load my wrapper functions (I cribbed your code).
/* Create the table of global functions. */
lua_createtable(L, 0, count(functions));
luaL_register(L, NULL, functions);
return 1;
After fixing up LUA_CPATH, the register function works but I'm getting an error from lua:
error loading module 'aes.core' from file 'lib/aes/core.so':
lib/aes/core.so: undefined symbol: lua_pushstring
I stripped the core.so function down to two functions (luaopen_aes_core and my_version) and have only calls to lua_pushstring, lua_createtable and luaL_register in it. Whichever one is referenced first throws an error, basically the same error as above.
I have a C driver that sets up my environment, calls luaL_newstate(), luaL_openlibs(), then calls lua_pushstring a couple of times to set up a environment table. Then it calls luaL_loadbuffer() and lua_pcall() to run the scripts.
The main program links in liblua.a and I've confirmed that lua_pushstring is in there. If I don't run the script that uses requires to load the library, everything works nicely.
I'm not sure what else to look at for this.