Committed to Lua 5.3, polyfilled (ew) the setfenv / getfenv functions.
* Fixed a crash where an improperly formatted subgame can crash the client. * Remove Lua 5.1 from CMakeLists.txt.master
parent
73c12a1de5
commit
8d6e19500a
|
@ -2,6 +2,5 @@
|
|||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/lib/assimp" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -19,12 +19,9 @@ set(MAIN_EXEC_NAME "Zepha")
|
|||
|
||||
project(${PROJECT_NAME})
|
||||
|
||||
|
||||
find_path(GLEW_HEADERS GL/glew.h)
|
||||
find_path(GLFW_HEADERS GLFW/glfw3.h)
|
||||
find_path(LUA_HEADERS lua.hpp
|
||||
/usr/include/lua5.1
|
||||
/usr/local/include/lua5.1
|
||||
/usr/include/lua5.3
|
||||
/usr/local/include/lua5.3)
|
||||
find_path(ASSIMP_HEADERS assimp/Importer.hpp)
|
||||
|
@ -109,7 +106,7 @@ else()
|
|||
endif()
|
||||
|
||||
# Link Lua 5.3.5
|
||||
find_library(LUA_LIB NAMES lua lua5.1 lua5.3)
|
||||
find_library(LUA_LIB NAMES lua lua5.3)
|
||||
target_link_libraries(${MAIN_EXEC_NAME} ${LUA_LIB})
|
||||
|
||||
# Link Noise
|
||||
|
|
|
@ -29,8 +29,8 @@ function zepha.block_interact(player, target)
|
|||
|
||||
local args = { target.dim, target.pos, player }
|
||||
local cb = zepha.server and "on_interact" or "on_interact_client"
|
||||
if type(def[cb]) == "function" then def[cb](unpack(args)) end
|
||||
zepha.trigger(cb, unpack(args))
|
||||
if type(def[cb]) == "function" then def[cb](table.unpack(args)) end
|
||||
zepha.trigger(cb, table.unpack(args))
|
||||
|
||||
return def.on_interact or def.on_interact_client
|
||||
end
|
||||
|
@ -80,12 +80,12 @@ function zepha.block_break(player, target)
|
|||
local args = { target.dim, target.pos, player }
|
||||
|
||||
local cb = zepha.server and "on_break" or "on_break_client"
|
||||
if type(def[cb]) == "function" then def[cb](unpack(args)) end
|
||||
zepha.trigger(cb, unpack(args))
|
||||
if type(def[cb]) == "function" then def[cb](table.unpack(args)) end
|
||||
zepha.trigger(cb, table.unpack(args))
|
||||
|
||||
target.dim:set_block(target.pos, "air")
|
||||
|
||||
local cb = zepha.server and "after_break" or "after_break_client"
|
||||
if type(def[cb]) == "function" then def[cb](unpack(args)) end
|
||||
zepha.trigger(cb, unpack(args))
|
||||
if type(def[cb]) == "function" then def[cb](table.unpack(args)) end
|
||||
zepha.trigger(cb, table.unpack(args))
|
||||
end
|
|
@ -1,4 +1,6 @@
|
|||
-- Load Libraries
|
||||
runfile(_PATH .. "modules/fenv")
|
||||
|
||||
runfile(_PATH .. "modules/gui")
|
||||
runfile(_PATH .. "modules/dump")
|
||||
runfile(_PATH .. "modules/math")
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
if not setfenv then
|
||||
_G['setfenv'] = function(fn, env)
|
||||
local i = 1
|
||||
while true do
|
||||
local name = debug.getupvalue(fn, i)
|
||||
if name == "_ENV" then
|
||||
debug.upvaluejoin(fn, i, (function()
|
||||
return env
|
||||
end), 1)
|
||||
break
|
||||
elseif not name then
|
||||
break
|
||||
end
|
||||
|
||||
i = i + 1
|
||||
end
|
||||
|
||||
return fn
|
||||
end
|
||||
end
|
||||
|
||||
if not getfenv then
|
||||
_G['getfenv'] = function(fn)
|
||||
local i = 1
|
||||
while true do
|
||||
local name, val = debug.getupvalue(fn, i)
|
||||
if name == "_ENV" then
|
||||
return val
|
||||
elseif not name then
|
||||
break
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
end
|
|
@ -31,7 +31,7 @@ void MenuSandbox::reset() {
|
|||
core = {};
|
||||
mod = {};
|
||||
lua = sol::state {};
|
||||
lua.open_libraries(sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::table);
|
||||
lua.open_libraries(sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::table, sol::lib::debug);
|
||||
|
||||
loadApi();
|
||||
}
|
||||
|
|
|
@ -170,8 +170,8 @@ void MainMenuScene::findSubgames() {
|
|||
|
||||
subgames.push_back({icon, {name, description, version}, subgameFolder.path});
|
||||
}
|
||||
catch(const std::string& e) {
|
||||
std::cout << Log::err << "Encountered an error while loading subgames:\n\t" << e << Log::endl;
|
||||
catch(const std::runtime_error e) {
|
||||
std::cout << Log::err << "Encountered an error while loading subgames:\n\t" << e.what() << Log::endl;
|
||||
}
|
||||
|
||||
cf_dir_next(&subgamesDir);
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
LocalLuaParser::LocalLuaParser(LocalSubgame& game): LuaParser(game), keybinds(this) {}
|
||||
|
||||
void LocalLuaParser::init(WorldPtr world, PlayerPtr player, ClientState& state) {
|
||||
lua.open_libraries(sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::table);
|
||||
lua.open_libraries(sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::table, sol::lib::debug);
|
||||
|
||||
loadApi(world, player);
|
||||
handler.executeMods(Util::bind_this(this, &LocalLuaParser::runFileSandboxed));
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
ServerLuaParser::ServerLuaParser(ServerSubgame& game) : LuaParser(game) {}
|
||||
|
||||
void ServerLuaParser::init(WorldPtr world, const std::string& path) {
|
||||
lua.open_libraries(sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::table);
|
||||
lua.open_libraries(sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::table, sol::lib::debug);
|
||||
|
||||
loadApi(world);
|
||||
handler.loadMods(static_cast<ServerSubgame&>(game), path + "mods");
|
||||
|
|
Loading…
Reference in New Issue