封装源码
extern "C"
{
#include "src/lua/include/lua.h"
#include "src/lua/include/lauxlib.h"
#include "src/lua/include/lualib.h"
}
#include <iostream>
#include <cstring>
#include <string>
#include <stdarg.h>
#include <unordered_map>
#include <vector>
#include "src/liblog/liblog.h"
using namespace std;
class NLua
{
public:
NLua()
{
}
~NLua()
{
if (m_state)
{
lua_close(m_state);
m_state = nullptr;
}
}
void NLua_info()
{
nLua_info(m_state);
}
bool NLua_init(const char *filename)
{
m_state = luaL_newstate();
if (!m_state)
{
if (lua_isstring(m_state, -1))
{
logw("Lua状态机初始化失败:[%s]\n", lua_tostring(m_state, -1));
lua_pop(m_state, 1);
}
return false;
}
luaL_openlibs(m_state);
int ret = luaL_dofile(m_state, filename);
if (0 != ret)
{
if (lua_isstring(m_state, -1))
{
logw("Lua库打开失败:[%s]\n", lua_tostring(m_state, -1));
lua_pop(m_state, 1);
}
return false;
}
return true;
}
bool NLua_function(const char *funcname)
{
m_param_number = 0;
int ret = lua_getglobal(m_state, funcname);
if (0 == lua_isfunc