62 lines
1.2 KiB
C++
62 lines
1.2 KiB
C++
#ifndef LUA_WRAPER_H
|
|
#define LUA_WRAPER_H
|
|
|
|
|
|
#include <string.h>
|
|
#include <iostream>
|
|
#include<typeinfo>
|
|
#include <iostream>
|
|
#include <map>
|
|
|
|
|
|
extern "C" {
|
|
#include "lua.h"
|
|
#include "lauxlib.h"
|
|
#include "lualib.h"
|
|
}
|
|
|
|
|
|
class LuaDelegate{
|
|
public:
|
|
LuaDelegate();
|
|
LuaDelegate(std::map<std::string, lua_CFunction>);
|
|
|
|
int DoFile(std::string);
|
|
void Stop();
|
|
int DoString(std::string);
|
|
int UpdateScript(std::string);
|
|
|
|
template <typename T,typename ... Types>
|
|
void pushstack(T arg1,Types... rest) {
|
|
const std::type_info &t1 = typeid(arg1);
|
|
pushstack(rest...);
|
|
}
|
|
template<typename... T>
|
|
void CallFuntion(std::string name,T... para){
|
|
int i = lua_getglobal(mVM,name.c_str());
|
|
if(i < 0){
|
|
return ;
|
|
}
|
|
pushstack(para...);
|
|
}
|
|
void PrintError(lua_State *L);
|
|
|
|
void OnSerialData(std::string);
|
|
void OnNetworkData(char*,char*,uint32_t port);
|
|
void OnNewTcpClient(std::string ip,uint32_t port,uint32_t sockptr);
|
|
void OnClientLeave(std::string ip,uint32_t port,uint32_t sockptr);
|
|
|
|
void DumpStack();
|
|
|
|
~LuaDelegate();
|
|
private:
|
|
lua_State *mVM;
|
|
std::string mFile;
|
|
std::map<std::string, lua_CFunction> mFunc;
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|