English 中文(简体)
采用菜单系统
原标题:Implementing lua callbacks for a menu system
  • 时间:2011-10-18 19:49:19
  •  标签:
  • c++
  • lua

在我们的菜单制度中,我们界定了Xml的菜单,其lu子用于菜单部分活动。 目前,每次都叫作背书,我们称之为缓慢载体。 我试图这样做,只是当菜单装满时。

我最初的想法是,维持每个菜单部分的卢布表,并在表格中增加一个新的反馈功能:

//create lua code that will assign a function to our table
std::string callback = "temp." + callbackName + " = function (" + params + ")" + luaCode + "end";

//push table onto stack
lua_rawgeti(L, LUA_REGISTRYINDEX, luaTableRef_);

//pop table from stack and set it as value of global "temp"
lua_setglobal(L, "temp");

//push new function onto stack
int error = luaL_loadstring(L, callback.c_str());
if ( error )
{   
    const char* errorMsg = lua_tostring(L, -1);
    Dbg::Printf("error loading the script  %s  : %s
", callbackName, errorMsg);
    lua_pop(L,1);
    return;
}

//call the lua code to insert the loaded function into the global temp table
if (lua_pcall(L, 0, 0, 0)) 
{
    Dbg::Printf("luascript: error running the script  %s 
", lua_tostring(L, -1));
    lua_pop(L, 1);
}

//table now has function in it

这似乎是一种ir。 是否有更好的办法使我能够把职能直接从lu子中分配到桌旁,而不必使用温带的全球变量和旋转液。

最佳回答
问题回答

暂无回答




相关问题
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?

热门标签