【发布时间】:2013-04-17 00:58:32
【问题描述】:
假设我有一个回调函数,当指定玩家死亡时执行。
function OnPlayerDeath(playerid)
end
我希望这个函数在 Lua C 模块中被调用,而不是放在 lua 脚本中:
static int l_OnPlayerConnect (lua_State * L) {
enum { lc_nformalargs = 1 };
lua_settop(L,1);
// so here I can use playerid argument - 1 arg
return 0;
}
在 C 中是否有可能接收到这个回调参数?
#define LUA extern "C" __declspec(dllexport) int __cdecl
LUA luaopen_mymodule(lua_State *L)
{
/* function OnPlayerConnect( playerid )
*
* end */
lua_pushcfunction(L,l_OnPlayerConnect);
lua_setfield(L,LUA_GLOBALSINDEX,"OnPlayerConnect"); //there's already OnPlayerConnect I just want to also call it here but I don't know how.
assert(lua_gettop(L) - lc_nextra == 0);
return 1;
}
我不想把这个函数压入 lua 栈,因为这个函数已经存在。 我只是希望它是已经存在的 Lua 函数。
【问题讨论】: