嗨!
我的问题很简单:我在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