Jump to content

Access Violation on C function exposed to Lua


Rick
 Share

Recommended Posts

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;
}

Link to comment
Share on other sites

  • 3 weeks later...

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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...