How can I pass arguments to my lua dll function?
I made a simple lua dll function:
static int functionName(lua_State *L, int arg1, char arg2[])
{
printf("running my dll:\n");
printf("passing number: %d passing string = %s",arg1,arg2);
return 0;
}
And use this in lua to run the function:
require "myTestDll";
myTestDll.functionName(1231544,"Hello World, I'm running my DLL.");
But the result is that it prints the wrong number and not even close to the correct string.
Functions you register to Lua must always have the same C or C++ signature:
int FuncName(lua_State*);They can take no more or less parameters than that.Lua parameters passed to registered functions are part of the
lua_State*. They are the first values placed on the Lua stack. So you can calllua_gettopto get the number of parameters. And you can use the usual Lua stack functions to pull them off of the stack.For example, if you want your function to have two parameters, where the first is a number and the second is a string, you do this: