Commit 1bde2fb4 authored by Chen Bill's avatar Chen Bill Committed by GitHub

add new option for interpreter to manage unsafe libraries (#778)

parent c06a0867
...@@ -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) {
lua_state = luaL_newstate(); lua_state = luaL_newstate();
current_state = lua_state; current_state = lua_state;
pduel = pd; pduel = pd;
...@@ -32,15 +32,20 @@ interpreter::interpreter(duel* pd): coroutines(256) { ...@@ -32,15 +32,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);
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,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