I have a C program that uses Lua to run some scripts. I need to open the Lua libraries via C code like luaopen_socket_core(myLuaState)
, for some reasons I can't load the modules from the Lua code, like socket = require "luasocket"
.
Once understood the idea of this program now I need to load a library called struct, so I added the struct.c
to my project, and when I tried to use its functions like struct.unpack
the runtimer complains that there is no global variable called struct
. Of course it was loaded with luaopen_struct(myLuaState)
instead of struct = require "struct"
which is forbidden for me.
Any suggestion about an way of having this struct
variable available?
Take a look at luaL_requiref
in the auxiliary library, which mimics require
called from Lua.
You probably called the open-function directly and forgot to set those variables manually, that function would do it all for you.