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 <> escreveu:
Try to write: attest.lua
function dump(x) for k,v in pairs(x) do print(k,v) end end
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
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.

static const luaL_Reg testsfuncs_lib[] = {
  {"atest1", atest1},
  {"atest2", atest2},

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

static const luaL_Reg loadedlibs[] = {
  {"atestsfuncs", luaopen_testsfuncs },

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 ( and )
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.

Ranier Vilela