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.
This commit is contained in:
parent
73c12a1de5
commit
8d6e19500a
1
.idea/vcs.xml
generated
1
.idea/vcs.xml
generated
@ -2,6 +2,5 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
<mapping directory="$PROJECT_DIR$/lib/assimp" vcs="Git" />
|
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -19,12 +19,9 @@ set(MAIN_EXEC_NAME "Zepha")
|
|||||||
|
|
||||||
project(${PROJECT_NAME})
|
project(${PROJECT_NAME})
|
||||||
|
|
||||||
|
|
||||||
find_path(GLEW_HEADERS GL/glew.h)
|
find_path(GLEW_HEADERS GL/glew.h)
|
||||||
find_path(GLFW_HEADERS GLFW/glfw3.h)
|
find_path(GLFW_HEADERS GLFW/glfw3.h)
|
||||||
find_path(LUA_HEADERS lua.hpp
|
find_path(LUA_HEADERS lua.hpp
|
||||||
/usr/include/lua5.1
|
|
||||||
/usr/local/include/lua5.1
|
|
||||||
/usr/include/lua5.3
|
/usr/include/lua5.3
|
||||||
/usr/local/include/lua5.3)
|
/usr/local/include/lua5.3)
|
||||||
find_path(ASSIMP_HEADERS assimp/Importer.hpp)
|
find_path(ASSIMP_HEADERS assimp/Importer.hpp)
|
||||||
@ -109,7 +106,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Link Lua 5.3.5
|
# 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})
|
target_link_libraries(${MAIN_EXEC_NAME} ${LUA_LIB})
|
||||||
|
|
||||||
# Link Noise
|
# Link Noise
|
||||||
|
@ -29,8 +29,8 @@ function zepha.block_interact(player, target)
|
|||||||
|
|
||||||
local args = { target.dim, target.pos, player }
|
local args = { target.dim, target.pos, player }
|
||||||
local cb = zepha.server and "on_interact" or "on_interact_client"
|
local cb = zepha.server and "on_interact" or "on_interact_client"
|
||||||
if type(def[cb]) == "function" then def[cb](unpack(args)) end
|
if type(def[cb]) == "function" then def[cb](table.unpack(args)) end
|
||||||
zepha.trigger(cb, unpack(args))
|
zepha.trigger(cb, table.unpack(args))
|
||||||
|
|
||||||
return def.on_interact or def.on_interact_client
|
return def.on_interact or def.on_interact_client
|
||||||
end
|
end
|
||||||
@ -80,12 +80,12 @@ function zepha.block_break(player, target)
|
|||||||
local args = { target.dim, target.pos, player }
|
local args = { target.dim, target.pos, player }
|
||||||
|
|
||||||
local cb = zepha.server and "on_break" or "on_break_client"
|
local cb = zepha.server and "on_break" or "on_break_client"
|
||||||
if type(def[cb]) == "function" then def[cb](unpack(args)) end
|
if type(def[cb]) == "function" then def[cb](table.unpack(args)) end
|
||||||
zepha.trigger(cb, unpack(args))
|
zepha.trigger(cb, table.unpack(args))
|
||||||
|
|
||||||
target.dim:set_block(target.pos, "air")
|
target.dim:set_block(target.pos, "air")
|
||||||
|
|
||||||
local cb = zepha.server and "after_break" or "after_break_client"
|
local cb = zepha.server and "after_break" or "after_break_client"
|
||||||
if type(def[cb]) == "function" then def[cb](unpack(args)) end
|
if type(def[cb]) == "function" then def[cb](table.unpack(args)) end
|
||||||
zepha.trigger(cb, unpack(args))
|
zepha.trigger(cb, table.unpack(args))
|
||||||
end
|
end
|
@ -1,4 +1,6 @@
|
|||||||
-- Load Libraries
|
-- Load Libraries
|
||||||
|
runfile(_PATH .. "modules/fenv")
|
||||||
|
|
||||||
runfile(_PATH .. "modules/gui")
|
runfile(_PATH .. "modules/gui")
|
||||||
runfile(_PATH .. "modules/dump")
|
runfile(_PATH .. "modules/dump")
|
||||||
runfile(_PATH .. "modules/math")
|
runfile(_PATH .. "modules/math")
|
||||||
|
35
assets/base/script/modules/fenv.lua
Normal file
35
assets/base/script/modules/fenv.lua
Normal file
@ -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 = {};
|
core = {};
|
||||||
mod = {};
|
mod = {};
|
||||||
lua = sol::state {};
|
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();
|
loadApi();
|
||||||
}
|
}
|
||||||
|
@ -170,8 +170,8 @@ void MainMenuScene::findSubgames() {
|
|||||||
|
|
||||||
subgames.push_back({icon, {name, description, version}, subgameFolder.path});
|
subgames.push_back({icon, {name, description, version}, subgameFolder.path});
|
||||||
}
|
}
|
||||||
catch(const std::string& e) {
|
catch(const std::runtime_error e) {
|
||||||
std::cout << Log::err << "Encountered an error while loading subgames:\n\t" << e << Log::endl;
|
std::cout << Log::err << "Encountered an error while loading subgames:\n\t" << e.what() << Log::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
cf_dir_next(&subgamesDir);
|
cf_dir_next(&subgamesDir);
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
LocalLuaParser::LocalLuaParser(LocalSubgame& game): LuaParser(game), keybinds(this) {}
|
LocalLuaParser::LocalLuaParser(LocalSubgame& game): LuaParser(game), keybinds(this) {}
|
||||||
|
|
||||||
void LocalLuaParser::init(WorldPtr world, PlayerPtr player, ClientState& state) {
|
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);
|
loadApi(world, player);
|
||||||
handler.executeMods(Util::bind_this(this, &LocalLuaParser::runFileSandboxed));
|
handler.executeMods(Util::bind_this(this, &LocalLuaParser::runFileSandboxed));
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
ServerLuaParser::ServerLuaParser(ServerSubgame& game) : LuaParser(game) {}
|
ServerLuaParser::ServerLuaParser(ServerSubgame& game) : LuaParser(game) {}
|
||||||
|
|
||||||
void ServerLuaParser::init(WorldPtr world, const std::string& path) {
|
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);
|
loadApi(world);
|
||||||
handler.loadMods(static_cast<ServerSubgame&>(game), path + "mods");
|
handler.loadMods(static_cast<ServerSubgame&>(game), path + "mods");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user