lua-users home
lua-l archive

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



Em ter., 27 de out. de 2020 às 10:29, Sergey Kovalev <kovserg33@gmail.com> escreveu:
Try to write: attest.lua
function dump(x) for k,v in pairs(x) do print(k,v) end end
dump(_G);
Thanks for the hint.

Added the line require "libtest", I don't know if it made a difference.
The dump suggested, show my module functions:
testfuncs  table: 000001A9740D72A0
like
io      table: 000001A9740D1780

Why Lua 5.4, do not find it in "testfuncs table"?
 
I think you just do not register your function in global variables.
In general if you write a module for lua it should use dynamic
linking. So you could use it with a simple require statement.
Well, I am registering like this.

libtest.c
static const luaL_Reg testsfuncs_lib[] = {
  {"atest1", atest1},
  {"atest2", atest2},
  {NULL, NULL}
};

LUAMOD_API int luaopen_testsfuncs (lua_State *L) {
  luaL_newlib(L,  testsfuncs_lib);
  return 1;
}

testinit.c
static const luaL_Reg loadedlibs[] = {
  {"atestsfuncs", luaopen_testsfuncs },
  {NULL, NULL}
};

LUALIB_API int luaopen_libtest(lua_State *L) {
    const luaL_Reg *lib;

    for (lib = loadedlibs; lib->func; ++lib) {
       luaL_requiref(L, lib->name, lib->func, 1);
       lua_pop(L, 1);
    }

return 1;
}

This is the way with 5.4?
 

For example using tcc (
http://download.savannah.gnu.org/releases/tinycc/ and
https://www.lua.org/ftp/lua-5.3.5.tar.gz )
Unfortunately, I have to use msvc.
 
int __declspec(dllexport) luaopen_example(lua_State* L) {
    lua_register(L, "msgbox",  lua_msgbox);
    return 0;
}
This is pre 5.4, works with 5.4 too?

Thanks for helping me with this trouble.

regards,
Ranier Vilela