【发布时间】:2016-02-06 19:34:28
【问题描述】:
喂!
我的问题很简单:我在extendedgamefunctions 类中有一个函数:
在标题中:
#include "Gameitems.h"
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
};
extern std::vector<std::vector<Gameitems>> items;
class A
{
A();
~A();
public:
static void messagewindow(lua_State*);
};
代码是:
Functions extfunctions;
A::A()
{}
A::~A()
{}
void A::messagewindow(lua_State *L)
{
string message =lua_tostring(L,0);
extfunctions.Messagewindow(message);
}
我想绑定另一个名为 Gamefunctions 的函数:
#include "Externedgamefunctions.h"
A egfunctions;
lua_State* L;
void Gamefunctions::luainit()
{
L = luaL_newstate();
/* load Lua base libraries */
luaL_openlibs(L);
lua_pushcfunction(L,&A::messagewindow);
lua_setglobal(L, "messagewindow");
}
而另一个类的函数是静态的,我得到这个错误:
Error 5 error C2664: 'lua_pushcclosure' : cannot convert parameter 2 from 'void (__cdecl *)(lua_State *)' to 'lua_CFunction' C:\Users\Bady\Desktop\MY Game\basicconfig\BlueButterfly\BlueButterfly\Gamefunctions.cpp 170
我不想在游戏函数中添加一个加号函数来获取消息窗口(除非我没有其他 coises),因为我直接编写了扩展的游戏函数,而不是制造一个无穷无尽的字符串怪物。
编辑: 差点忘了:Lua 5.2 和 c++11
【问题讨论】:
标签: c++ lua bind lua-api static-functions