Calling C function from a dll, in lua

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
soulaymenc
Prole
Posts: 36
Joined: Thu Jul 11, 2013 2:03 pm
Contact:

Calling C function from a dll, in lua

Post by soulaymenc »

hello lovers, I have been strugglin' for two days to make a DLL in C then call its functions from a lua script.
The C functions are to deal with wiiuse library, so I can use this feature in Love games.
So here is the code:

Code: Select all

#include "wiiuse.h"
#include "lua/lua.h"
#include "lua/lauxlib.h"

static int wiiInit(lua_State *L)
{
  int x = lua_tointeger(L, 1);
  printf("x = %d\n", x);
  //wiimote ** wm = wiiuse_init(x);
  //lua_pushinteger(L, wm);
  return 1;
}

int luaopen_wiilib (lua_State *L) {
	struct luaL_Reg driver[] = {
		{"wiiInit", wiiInit},
		{NULL, NULL}
	};
	luaL_openlib(L, "wiilib", driver, 0);
	return 1;
}
and the Lua code

Code: Select all

wiilib = require("wiilib")
wiilib.wiiInit(1, 2, 3)
So the thing is the output is always

Code: Select all

x = 0
It looks like the C functions from the dll file are not able to read arguments from Lua :(

What am I missing here? Any ideas, suggestions?
By the way the dll is compiled along with lua 5.2 and the wiiuse libraries.

Thanks <3
This world is so strange.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Calling C function from a dll, in lua

Post by bartbes »

You need to compile against lua 5.1 or luajit, so maybe that will fix it?
User avatar
soulaymenc
Prole
Posts: 36
Joined: Thu Jul 11, 2013 2:03 pm
Contact:

Re: Calling C function from a dll, in lua

Post by soulaymenc »

Thanks for your reply :)

I compiled it using the latest version of lua 5.2.3, is that the problem maybe?
This world is so strange.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 60 guests