nim_duilib/examples/proto_debuger/lua_wraper.h

113 lines
2.4 KiB
C
Raw Normal View History

2021-11-19 00:37:35 +08:00
#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"
}
2021-11-21 13:47:19 +08:00
class LuaDelegate {
2021-11-19 00:37:35 +08:00
public:
LuaDelegate();
2021-11-21 13:47:19 +08:00
LuaDelegate(std::map<std::string, lua_CFunction>);
2021-11-19 00:37:35 +08:00
int DoFile(std::string);
void Stop();
int DoString(std::string);
int UpdateScript(std::string);
2021-11-21 13:47:19 +08:00
void pushstack(lua_Number arg) {
lua_pushnumber(mVM, arg);
2021-11-19 00:37:35 +08:00
}
2021-11-21 13:47:19 +08:00
void pushstack(lua_Integer arg) {
lua_pushinteger(mVM, arg);
}
void pushstack(void* arg) {
lua_pushlightuserdata(mVM, arg);
}
void pushstack(const char* arg) {
lua_pushstring(mVM,arg);
}
void pushstack(bool arg) {
lua_pushboolean (mVM, arg);
}
void pushstack(std::string arg) {
lua_pushstring(mVM, arg.c_str());
}
void pushstack(lua_CFunction fn, int n) {
lua_pushcclosure(mVM, fn, n);
}
2021-11-21 13:47:19 +08:00
template <typename ... Types>
void pushstack(lua_Number arg1, Types... rest) {
lua_pushnumber(mVM, arg1);
pushstack(rest...);
}
template <typename ... Types>
void pushstack(lua_Integer arg1, Types... rest) {
lua_pushinteger (mVM, arg1);
pushstack(rest...);
}
template <typename ... Types>
void pushstack(bool arg1, Types... rest) {
lua_pushboolean(mVM, arg1);
pushstack(rest...);
}
template <typename ... Types>
void pushstack(std::string arg1, Types... rest) {
lua_pushstring(mVM, arg1.c_str());
pushstack(rest...);
}
template <typename ... Types>
void pushstack(void* arg1, Types... rest) {
lua_pushlightuserdata(mVM, arg1);
pushstack(rest...);
}
template <typename ... Types>
void pushstack(lua_CFunction fn, int n, Types... rest) {
lua_pushcclosure(mVM, fn,n);
pushstack(rest...);
}
template <typename ... Types>
void pushstack(const char* arg1, Types... rest) {
lua_pushstring(mVM, arg1);
pushstack(rest...);
}
2021-11-19 00:37:35 +08:00
template<typename... T>
void CallFuntion(std::string name,T... para){
int i = lua_getglobal(mVM,name.c_str());
if(i < 0){
return ;
}
pushstack(para...);
}
2021-11-21 13:47:19 +08:00
2021-11-19 00:37:35 +08:00
void PrintError(lua_State *L);
int BindFunction(std::string name, lua_CFunction);
void OnSerialData(std::string);
2021-11-19 00:37:35 +08:00
void DumpStack();
~LuaDelegate();
private:
lua_State *mVM;
std::string mFile;
std::string mScript;
2021-11-19 00:37:35 +08:00
std::map<std::string, lua_CFunction> mFunc;
};
#endif