English 中文(简体)
当需要履行一项职能时,即由卢阿指挥
原标题:Get the lua command when a c function is called
  • 时间:2010-05-25 18:02:31
  •  标签:
  • c++
  • c
  • lua

附录一对卢阿的许多不同功能名称进行了登记,以在C中担任相同职务。 现在,每当我履行C职能时,是否有办法确定援引哪些职能名称?

例如:

int runCommand(lua_State *lua)
{
  const char *name = // getFunctionName(lua) ? how would I do this part
  for(int i = 0; i < functions.size; i++)
    if(functions[i].name == name)
      functions[i].Call()
}

int main()
{
  ...

  lua_register(lua, "delay", runCommand);
  lua_register(lua, "execute", runCommand);
  lua_register(lua, "loadPlugin", runCommand);
  lua_register(lua, "loadModule", runCommand);
  lua_register(lua, "delay", runCommand);
}

因此,我如何获得所谓的那种职能的名称?

最佳回答
问题回答

http://pgl.yo.org/luai/i/lua_getinfo”rel=“nofollow noreferer”>。

这一工作可以:

const char* lua_getcurrentfunction(lua_State* L) {
    lua_Debug ar;
    lua_getstack(L, 1, &ar);
    lua_getinfo(L, "f", &ar);
    return ar.name;
}

有一个洞穴:

名称:特定职能的合理名称。 由于卢阿的职能是头等值,因此没有固定名称:有些职能可能是多种全球变量的价值,而其他职能可能只储存在一个表层。 lua_getinfo功能检查了如何要求该功能找到合适的名称。 如果找不到名字,那么名字就交给民族解放军。

另一种解决办法是,为Lua环境表登记一个表,该表采用_index metamethod,用于发出这些功能电话。

不幸的是,这是不可能的,除其他外,因为卢阿的职能实际上根本没有名称。 (Consider: (loadstring (“a=1”)) 正在执行从上填满的无名功能。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签