lua-users home
lua-l archive

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


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

For example using tcc (
http://download.savannah.gnu.org/releases/tinycc/ and
https://www.lua.org/ftp/lua-5.3.5.tar.gz )
[build-lua.cmd]
set src=lua-5.3.5\src
tcc -o lua.dll -I%src% -shared -DLUA_BUILD_AS_DLL ^
    %src%\lauxlib.c ^
    %src%\lbaselib.c ^
    %src%\lbitlib.c ^
    %src%\lcorolib.c ^
    %src%\ldblib.c ^
    %src%\liolib.c ^
    %src%\lmathlib.c ^
    %src%\loslib.c ^
    %src%\lstrlib.c ^
    %src%\ltablib.c ^
    %src%\lutf8lib.c ^
    %src%\loadlib.c ^
    %src%\linit.c ^
    %src%\lapi.c ^
    %src%\lcode.c ^
    %src%\lctype.c ^
    %src%\ldebug.c ^
    %src%\ldo.c ^
    %src%\ldump.c ^
    %src%\lfunc.c ^
    %src%\lgc.c ^
    %src%\llex.c ^
    %src%\lmem.c ^
    %src%\lobject.c ^
    %src%\lopcodes.c ^
    %src%\lparser.c ^
    %src%\lstate.c ^
    %src%\lstring.c ^
    %src%\ltable.c ^
    %src%\ltm.c ^
    %src%\lundump.c ^
    %src%\lvm.c ^
    %src%\lzio.c

tcc -o lua.exe -I%src% -DLUA_BUILD_AS_DLL -L. lua.def ^
    %src%\lua.c

[example.c]
#include <windows.h>
#include "lauxlib.h"

/* Pop-up a Windows message box with your choice of message and caption */
int lua_msgbox(lua_State* L) {
    const char* message = luaL_checkstring(L, 1);
    const char* caption = luaL_optstring(L, 2, "");
    int result = MessageBox(NULL, message, caption, MB_OK);
    lua_pushnumber(L, result);
    return 1;
}

int __declspec(dllexport) luaopen_example(lua_State* L) {
    lua_register(L, "msgbox",  lua_msgbox);
    return 0;
}

[build-example.cmd]
set inc=lua-5.3.5\src
tcc -o example.dll -L. -l%inc% -Ilua -shared example.c

[example.lua]
require "example"
msgbox("hello","example.dll")

Run with: lua.exe example.lua

вт, 27 окт. 2020 г. в 15:18, Ranier Vilela <ranier.vf@gmail.com>:
>
> Em ter., 27 de out. de 2020 às 09:06, Sergey Kovalev <kovserg33@gmail.com> escreveu:
>>
>> Why did you use lua5.4.2-static.lib for dll ?
>
> Because, lua functions (ABI) are used inside DLL module.
>
> regards,
> Ranier Vilela