Rick Posted June 11, 2015 Share Posted June 11, 2015 I've exposed C functions inside DLL's just fine to lua, but now I'm trying to expose C functions from the LE exe to lua and getting an access violation error when I call lua_pushcfunction(). I can call the C function just fine in the same place so not sure why the access violation is happening. bool App::Start() { // calling the function I"m trying to register works so the function is valid UpdateStat(Interpreter::L); // register lua to c++ functions lua_pushcfunction(Interpreter::L, UpdateStat); // this fails with access violation error lua_setglobal(Interpreter::L, "UpdateStat"); } static int UpdateStat(lua_State* L) { return 0; } Quote Link to comment Share on other sites More sharing options...
Rick Posted June 11, 2015 Author Share Posted June 11, 2015 Bah nvm. Forgot to call GetStackSize() before doing this. 1 Quote Link to comment Share on other sites More sharing options...
miko93 Posted June 27, 2015 Share Posted June 27, 2015 Rather than creating a new topic, I feel free to jump in here with a related question. Anyone got objects (Vec3, in my case) passed between lua and C? For e.g. int types, I would do like (calling from lua into C) lua_register(Interpreter::L, "CalledFromLua", CalledFromLua); extern "C" int CalledFromLua(lua_State* L) { int i = lua_tointeger(Leadwerks::Interpreter::L,1) CallMyFunc(i); return 0; } and (calling from C into lua) void CalledFromC(int i) { lua_getglobal(Leadwerks::Interpreter::L, "AFunction"); if (!lua_isfunction(Leadwerks::Interpreter::L, -1)) { lua_pop(Leadwerks::Interpreter::L, 1); return; } lua_pushinteger(Leadwerks::Interpreter::L, i); if (lua_pcall(Leadwerks::Interpreter::L, 1, 0, 0) != 0) { printf("Callback_ClientPosRot ERROR: %s\n", lua_tostring(Leadwerks::Interpreter::L, -1)); return; } } But with e.g. Vec3, this seems to be a bit more complicated. Like, using 'userdata' or such things. Any hints? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.