Commit 3d8b79df authored by salix5's avatar salix5 Committed by GitHub

Refactor interpreter constructor and duel constructor (#794)

parent 08444f88
...@@ -31,8 +31,8 @@ duel::~duel() { ...@@ -31,8 +31,8 @@ duel::~duel() {
delete pgroup; delete pgroup;
for(auto& peffect : effects) for(auto& peffect : effects)
delete peffect; delete peffect;
delete lua;
delete game_field; delete game_field;
delete lua;
} }
void duel::clear() { void duel::clear() {
for(auto& pcard : cards) for(auto& pcard : cards)
......
...@@ -14,13 +14,10 @@ ...@@ -14,13 +14,10 @@
#include "ocgapi.h" #include "ocgapi.h"
#include "interpreter.h" #include "interpreter.h"
interpreter::interpreter(duel* pd, bool enable_unsafe_libraries): coroutines(256) { interpreter::interpreter(duel* pd, bool enable_unsafe_libraries) : coroutines(256), pduel(pd) {
lua_state = luaL_newstate(); lua_state = luaL_newstate();
current_state = lua_state; current_state = lua_state;
pduel = pd;
std::memcpy(lua_getextraspace(lua_state), &pd, LUA_EXTRASPACE); //set_duel_info std::memcpy(lua_getextraspace(lua_state), &pd, LUA_EXTRASPACE); //set_duel_info
no_action = 0;
call_depth = 0;
//Initial //Initial
luaL_requiref(lua_state, "base", luaopen_base, 0); luaL_requiref(lua_state, "base", luaopen_base, 0);
lua_pop(lua_state, 1); lua_pop(lua_state, 1);
......
...@@ -44,14 +44,14 @@ public: ...@@ -44,14 +44,14 @@ public:
using param_list = std::list<std::pair<lua_param, LuaParamType>>; using param_list = std::list<std::pair<lua_param, LuaParamType>>;
duel* pduel; duel* pduel;
char msgbuf[64]; char msgbuf[64]{};
lua_State* lua_state; lua_State* lua_state;
lua_State* current_state; lua_State* current_state;
param_list params; param_list params;
param_list resumes; param_list resumes;
coroutine_map coroutines; coroutine_map coroutines;
int32_t no_action; int32_t no_action{};
int32_t call_depth; int32_t call_depth{};
explicit interpreter(duel* pd, bool enable_unsafe_libraries); explicit interpreter(duel* pd, bool enable_unsafe_libraries);
~interpreter(); ~interpreter();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment