59 lines
998 B
C++
59 lines
998 B
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;
|
||
|
}
|
||
|
|
||
|
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_loadfile(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);
|
||
|
}
|