lua在newindex是函数时如何获得参数列表
c++ 代码:
// luaEvent.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
#pragma comment(lib, "lua5.1.lib")
static int newindexFunc(lua_State* pState)
{
printf("newindexFunc call,key=%s\n", lua_tostring(pState, 2));
if (lua_type(pState, 3) == LUA_TFUNCTION)
{
//这里如何知道函数的列表
}
else
{
//直接赋值到_G
lua_getglobal(pState, "_G");
lua_pushstring(pState, lua_tostring(pState, 2));
lua_pushvalue(pState, 3);
lua_settable(pState, -3);
lua_pop(pState, 1);
return 1;
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
lua_State* pState = lua_open();
luaL_openlibs(pState);
lua_pushthread(pState);
//新建新的全局表
lua_newtable(pState);
{
//为这个全局表设置元表
luaL_newmetatable(pState, "_new_global");
lua_pushstring(pState, "__index");
lua_getglobal(pState, "_G");
lua_settable(pState, -3);
lua_pushstring(pState, "__newindex");
lua_pushcfunction(pState, newindexFunc);
lua_settable(pState, -3);
lua_setmetatable(pState, -2);
}
//改变全局环境
if (lua_setfenv(pState, -2))
printf("lua_setfenv succeed!\n");
lua_pop(pState, 1);
//
if (luaL_dofile(pState, "event.lua"))
{
printf("%s\n", lua_tostring(pState, -1));
lua_pop(pState, 1);
}
lua_close(pState);
return 0;
}
lua代码:
a = "hehe"
print("a=", a)
b = function(x)
print("b call", x)
end
_G.c = function(y)
print("_G.c call", y)
end
问题:在c++代码的newindexFunc里当新加一个函数时 我怎么知道他的参数列表(即怎么知道写的是x)