2021-04-14 16:33:28 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:52:05 +00:00
|
|
|
void LuaDelegate::OnDataRecv(){
|
|
|
|
int i = lua_getglobal(mVM,"add");
|
|
|
|
lua_pushstring(mVM,"test");
|
|
|
|
lua_pushnumber(mVM,1);
|
|
|
|
lua_call(mVM,2,0);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-14 16:33:28 +00:00
|
|
|
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); //打开标准库
|
2021-04-14 16:52:05 +00:00
|
|
|
int ret = luaL_dofile(mVM, path.toStdString().c_str());
|
2021-04-14 16:33:28 +00:00
|
|
|
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);
|
|
|
|
}
|