Commit 292e0b0e authored by nanahira's avatar nanahira Committed by GitHub

Merge branch 'master' into patch-memtrack

parents 9198f9e4 1bde2fb4
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "buffer.h" #include "buffer.h"
duel::duel() { duel::duel() {
lua = new interpreter(this); lua = new interpreter(this, false);
game_field = new field(this); game_field = new field(this);
game_field->temp_card = new_card(TEMP_CARD_ID); game_field->temp_card = new_card(TEMP_CARD_ID);
message_buffer.reserve(SIZE_MESSAGE_BUFFER); message_buffer.reserve(SIZE_MESSAGE_BUFFER);
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "ocgapi.h" #include "ocgapi.h"
#include "interpreter.h" #include "interpreter.h"
interpreter::interpreter(duel* pd): coroutines(256) { interpreter::interpreter(duel* pd, bool enable_unsafe_libraries): coroutines(256) {
mem_tracker = new LuaMemTracker(YGOPRO_LUA_MEMORY_SIZE); mem_tracker = new LuaMemTracker(YGOPRO_LUA_MEMORY_SIZE);
lua_state = lua_newstate(LuaMemTracker::AllocThunk, mem_tracker); lua_state = lua_newstate(LuaMemTracker::AllocThunk, mem_tracker);
current_state = lua_state; current_state = lua_state;
...@@ -33,15 +33,20 @@ interpreter::interpreter(duel* pd): coroutines(256) { ...@@ -33,15 +33,20 @@ interpreter::interpreter(duel* pd): coroutines(256) {
lua_pop(lua_state, 1); lua_pop(lua_state, 1);
luaL_requiref(lua_state, "math", luaopen_math, 1); luaL_requiref(lua_state, "math", luaopen_math, 1);
lua_pop(lua_state, 1); lua_pop(lua_state, 1);
if (enable_unsafe_libraries) {
luaL_requiref(lua_state, "io", luaopen_io, 1);
lua_pop(lua_state, 1);
}
auto nil_out = [&](const char* name) { auto nil_out = [&](const char* name) {
lua_pushnil(lua_state); lua_pushnil(lua_state);
lua_setglobal(lua_state, name); lua_setglobal(lua_state, name);
}; };
nil_out("collectgarbage"); nil_out("collectgarbage");
#ifndef ENABLE_UNSAFE_LIBRARIES if (!enable_unsafe_libraries) {
nil_out("dofile"); nil_out("dofile");
nil_out("loadfile"); nil_out("loadfile");
#endif // ENABLE_UNSAFE_LIBRARIES }
//open all libs //open all libs
scriptlib::open_cardlib(lua_state); scriptlib::open_cardlib(lua_state);
scriptlib::open_effectlib(lua_state); scriptlib::open_effectlib(lua_state);
......
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
int32_t no_action; int32_t no_action;
int32_t call_depth; int32_t call_depth;
explicit interpreter(duel* pd); explicit interpreter(duel* pd, bool enable_unsafe_libraries);
~interpreter(); ~interpreter();
void register_card(card* pcard); void register_card(card* pcard);
......
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