Recently I've been trying to get to expose c functions to lua. Which had some problems and I'm still testing around but I managed to make it work. Atleast it works in regular 5.1 lua, but everytime I try to require the file into main.lua and execute main.lua with love it crashes. No error at all it just closes itself.
main.lua
Code: Select all
local mylib
print(pcall(function() mylib = require("mylib") end)) --prints nothing
function love.draw()
love.graphics.rectangle("fill",0,0,200,200)
end
Code: Select all
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
static int c_swap (lua_State *L) {
double arg1 = luaL_checknumber (L, 1);
double arg2 = luaL_checknumber (L, 2);
lua_pushnumber(L, arg2);
lua_pushnumber(L, arg1);
return 2;
}
static const struct luaL_Reg func[] = {
{"c_swap", c_swap},
{NULL, NULL}
};
__declspec(dllexport) int luaopen_mylib (lua_State *L){
luaL_register(L, "mylib", func);
return 1;
}
Code: Select all
gcc mod.c -shared -o mylib.dll -fPIC -llua
When I require the dll with regular lua it works perfectly fine. I can all mylib.c_swap(1,2) and it'll work but in love it shutsdown the program instantly. I've tried searching for awnsers on the internet but I couldn't find anything. I'm completely lost on this one.
lua 5.1 and löve are 32 bit. Mingw is also 32 bit.
All of the files are in the same directory.