I remember someone having a similar problem, here: https://love2d.org/forums/viewtopic.php?f=4&t=88104
Maybe this helps them.
Calling C dll from love2d
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Calling C dll from love2d
On windows you should use __declspec(dllexport).
Minimal crossplatfom library looks like this.
Here no usage of lua_reg, but nothing global is created.
So usage on lua side is:
Also you should to compile it to target lua version and platform (using luajit lua51.lib and same as your love x86_32/x86_64 target)
Minimal crossplatfom library looks like this.
Code: Select all
#include "lua/lua.h"
#include "lua/lauxlib.h"
int lua_summ(lua_State *L){
double a = luaL_checknumber(L, 1); /* get first arg */
double b = luaL_checknumber(L, 2); /* get second arg */
lua_pushnumber(L, a + b); /* returning value to lua */
return 1; /* count of args returned to lua */
}
#if defined(_WIN32) || defined(_WIN64) /* windows compat */
__declspec(dllexport)
#endif
int luaopen_mylib(lua_State *L) { /* compile it to mylib.dll or libmylib.so */
lua_newtable(L); /* create table */
lua_pushstring(L, "summ"); /* push "summ" as key*/
lua_pushcfunction(L, lua_summ); /* push lua_summ as value*/
lua_rawset(L, -3); /* assign key and value to this table (it gone from stack, but not table) */
return 1; /* return table to lua */
}
So usage on lua side is:
Code: Select all
local lib = require'mylib'
print(lib.summ(10, 20)) --> 30
Science and violence
Who is online
Users browsing this forum: No registered users and 2 guests