proto-debuger/protoDebuger/lua_wraper.cpp

69 lines
1.1 KiB
C++

#include "lua_wraper.h"
void LuaDelegate::Stop()
{
}
int LuaDelegate::DoString(QString scr)
{
if (mVM != nullptr){
int ret = luaL_dostring(mVM,scr.toStdString().c_str());
if (ret > 0){
printf("lua error");
return -1;
}
}
return 0;
}
void LuaDelegate::OnDataRecv(){
int i = lua_getglobal(mVM,"add");
lua_pushstring(mVM,"test");
lua_pushnumber(mVM,1);
lua_call(mVM,2,0);
}
LuaDelegate::~LuaDelegate()
{
if(nullptr != mVM){
lua_close(mVM);
}
}
LuaDelegate::LuaDelegate():
mVM(nullptr)
{
mVM = luaL_newstate(); //打开lua
if(nullptr != mVM){
printf("shit is nullptr");
}
}
int LuaDelegate::DoFile(QString path)
{
if(mVM != nullptr){
luaL_openlibs(mVM); //打开标准库
int ret = luaL_dofile(mVM, path.toStdString().c_str());
if (ret > 0){
printf("lua error");
return -1;
}
}
return 0;
}
void TestLua()
{
LuaDelegate v;
qDebug()<<typeid (int).name();
v.DoFile("Test.lua");
v.CallFuntion<int,void*,bool>("test",13,(void *)"sds",false);
}