English 中文(简体)
在C++的Lua表格中规定职能
原标题:Calling functions in a Lua table from C++
  • 时间:2009-12-11 15:06:21
  •  标签:
  • c++
  • lua
  • swig

例如,有一个Lua。 表/目标:

bannana

本表的功能是:chew,即参数

bannana.chew(5)

我也使用了SWIG,例如有一组<代码>。 CPerson:

class CPerson {
    public:
        // ....
        void Eat();
        // ....
};

我可以从卢阿获得一例该物体:

person = engine:getPerson()

我需要做的是以下卢阿法典:

person = engine:getPerson()
person:Eat(bannana)

在<编码>人:eat 上,chew功能载于banna的表格中,通过一个参数。

由于在C++中实施了<条码>CPerson,实施<条码>Eat(<>>>>/code>(假定< 条码><<>erson/code>类别已经有一个国名?

www.un.org/Depts/DGACM/index_spanish.htm Edit1: 我不想知道如何将C++级班级与卢阿挂钩,我已经拥有SWIG为我这样做,我想知道如何在卢阿表内从C++上调罗阿的功能。

www.un.org/Depts/DGACM/index_spanish.htm Edit2: 。 CPerson 类别已经有国名/参比,的功能签名 Eat方法可由回答者改动。

最佳回答

忽略检查错误......

lua_getglobal(L, "banana"); // or get  banana  from person:Eat()
lua_getfield(L, -1, "chew");
lua_pushinteger(L, 5);
lua_pcall(L, 1, 0, 0);
问题回答

或许“Simpler Cpp Bled





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

热门标签