Since you're refusing to provide your code, which is not helping at all, let me provide an example.
Setup of Lua state (C side):
lua_State *L = luaL_newstate();
//Set your userdata as a global
lua_pushlightuserdata(L, mypointer);
lua_setglobal(L, "mypointer");
//Setup my function
lua_pushcfunction(L, my_fct_name);
lua_setglobal(L, "my_fct_name");
//Load your script - luaScript is a null terminated const char* buffer with my script
luaL_loadstring(L, luaScript);
//Call the script (no error handling)
lua_pcall(L, 0, 0, 0);
Lua code V1:
my_fct_name(mypointer)
Lua code V2:
my_fct_name()
In the V1 you would get your pointer like this, since you provide it as an argument:
int my_fct_name(lua_State *L)
{
void *myPtr = lua_touserdata(L, 1);
//Do some stuff
return 0;
}
In the V2, you would have to get it from the globals table (which would work for V1 as well)
int my_fct_name(lua_State *L)
{
lua_getglobal(L, "mypointer");
void *myPtr = lua_touserdata(L, -1); //Get it from the top of the stack
//Do some stuff
return 0;
}
Have a look at the Lua Reference Manual and Programming in Lua. Mind you that the book that is available online is based on Lua 5.0, so it's not completely up to date, but should be sufficient for learning basics of interacting between C and Lua.