lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I've got a C program that Lua could return a function to and I'd like to save that function to call later when an event occurs.  What do I need to save so I can call the function?  How do I call the function?

Here is some example code I hope clarifys things:
--------------------
static void get_value_from_lua(lua_State *L, int index)
{
  ...
  t = lua_type(L, index);

  switch (t)
  {
    ...
    case LUA_TFUNCTION: /* function */
      // What to save here so lua_callback() function to call. luaL_ref? lua_topointer?
      // setup callback
      break;
    case LUA_TSTRING:  /* strings */
      value = lua_tostring(L, index);
      break;
    ...
}

static int lua_callback()
{
  // call the function staved in get_value_from_lua()
}
--------------------

--Robert