如果我定义一个" local"功能,如:
本地功能调度(存档) 和coroutine.resume(yielder) 端
...我想从C ++调用这个函数,我不认为我可以使用 lua_getglobal()调用:
m_pThreadState = lua_newthread(m_MasterLuaState);
//Load/define the above "Dispatch" routine local to this thread.
luaL_loadbuffer(m_pThreadState, m_ScriptBody, strlen(m_ScriptBody),"Console");
lua_getglobal(m_pThreadState, "Dispatch"); //UH-OH!! PROBLEM HERE!!
lua_pcall(m_pThreadState, 1, 0, 0);
那么如何指定/推送本地功能" Dispatch"准备好了 电话?我再次假设我不能使用lua_getglobal()调用,因为 " Dispatch"功能定义为" local"到m_pThreadState。什么 我该怎么做?
答案 0 :(得分:4)
您无法从C访问本地变量(除了调试API,但我不认为这是您想要的)。
局部变量(和函数,因为它们是变量)就是它们的本地变量,即只能从它们周围的范围内访问。
所以你有两个选择: