Reputation: 1389
I have Lua 5.3.5 64-bit installed on my machine. I am compiling a 64-bit dll
to test the c api process. Here is my file, driver.c
:
#define LUA_LIB
#include "lua/lua.h"
#include "lua/lualib.h"
#include "lua/lauxlib.h"
static int returnone(lua_State *L) {
return 1;
}
static const luaL_Reg lualib[] = {
{"returnone", returnone},
{NULL, NULL}
};
int luaopen_lualib(lua_State *L) {
luaL_newlib(L, lualib);
return 1;
}
This outputs to lualib.dll
I created a script, test.lua
in the same directory as lualib.dll
.
require("lualib");
I get this:
$ lua.exe test.lua
C:\Program Files\Lua\lua.exe: error loading module 'lualib' from file '.\lualib.dll':
The specified procedure could not be found.
stack traceback:
[C]: in ?
[C]: in function 'require'
test.lua:1: in main chunk
[C]: in ?
Then I try
print(package.loadlib("lualib", "luaopen_lualib"));
And I get
$ lua.exe test.lua
nil The specified procedure could not be found.
init
I am stumped. Where's my library?
Upvotes: 2
Views: 1612
Reputation: 2938
When building to Lua module to windows DLL you need to use __declspec(dllexport)
e.g. this should be enough for the most simple cases:
__declspec(dllexport) int luaopen_lualib(lua_State *L) {
luaL_newlib(L, lualib);
return 1;
}
Please refer to Building Modules on lua-users.
As for a more verbose example I would suggest luasocket: source, header.
Upvotes: 5