2021-04-04 18:32:21 +00:00
|
|
|
#ifndef LUA_WRAPER_H
|
|
|
|
#define LUA_WRAPER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
2021-04-14 16:33:28 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <iostream>
|
|
|
|
#include<typeinfo>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
2021-04-04 18:32:21 +00:00
|
|
|
extern "C" {
|
|
|
|
#include "lua.h"
|
|
|
|
#include "lauxlib.h"
|
|
|
|
#include "lualib.h"
|
|
|
|
}
|
2021-04-17 17:57:39 +00:00
|
|
|
#include "lua_bind.h"
|
2021-04-14 16:33:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LuaDelegate{
|
|
|
|
public:
|
|
|
|
LuaDelegate();
|
|
|
|
int DoFile(QString);
|
|
|
|
void Stop();
|
|
|
|
int DoString(QString);
|
2021-09-01 16:16:47 +00:00
|
|
|
int UpdateScript(QString);
|
|
|
|
|
2021-04-14 16:33:28 +00:00
|
|
|
void pushstack() {
|
|
|
|
// const std::type_info &t1 = std::bad_typeid(arg1);
|
|
|
|
// std::cout << t1.name() << std::endl;
|
2021-04-04 18:32:21 +00:00
|
|
|
}
|
2021-04-14 16:33:28 +00:00
|
|
|
//单参数模板
|
|
|
|
template <typename T,typename ... Types>
|
|
|
|
void pushstack(T arg1,Types... rest) {
|
|
|
|
const std::type_info &t1 = typeid(arg1);
|
|
|
|
qDebug() <<arg1 << " "<< t1.name() << " type ";
|
|
|
|
pushstack(rest...);
|
2021-04-13 17:28:19 +00:00
|
|
|
}
|
2021-04-14 16:33:28 +00:00
|
|
|
template<typename... T>//类的成员函数是模板
|
|
|
|
void CallFuntion(QString name,T... para){
|
|
|
|
int i = lua_getglobal(mVM,name.toStdString().c_str());
|
|
|
|
if(i < 0){
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
pushstack(para...);
|
|
|
|
}
|
2021-04-20 15:35:18 +00:00
|
|
|
void PrintError(lua_State *L);
|
2021-04-14 16:52:05 +00:00
|
|
|
/* 收到数据发送给lua层进行处理*/
|
2021-05-03 08:49:33 +00:00
|
|
|
void OnSerialData(QString);
|
|
|
|
void OnNetworkData(char*,char*,uint32_t port);
|
2021-09-09 16:22:33 +00:00
|
|
|
void OnNewTcpClient(QString ip,uint32_t port,uint32_t sockptr);
|
|
|
|
void OnClientLeave(QString ip,uint32_t port,uint32_t sockptr);
|
|
|
|
|
2021-04-18 15:16:03 +00:00
|
|
|
void DumpStack();
|
2021-04-14 16:33:28 +00:00
|
|
|
|
|
|
|
~LuaDelegate();
|
|
|
|
private:
|
|
|
|
lua_State *mVM;
|
|
|
|
QString mFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestLua();
|
|
|
|
|
|
|
|
|
2021-04-04 18:32:21 +00:00
|
|
|
#endif // LUA_WRAPER_H
|
2021-04-14 16:33:28 +00:00
|
|
|
|