Change Lua global namespace to "zepha"

master
Nicole Collings 2019-09-08 11:26:53 -07:00
parent 0d97fdf779
commit c7a8fea587
58 changed files with 181 additions and 171 deletions

View File

@ -1,11 +1,11 @@
dofile("zeus:default/blocks/bush_stem")
dofile("zeus:default/blocks/dirt")
dofile("zeus:default/blocks/grass")
dofile("zeus:default/blocks/leaves")
dofile("zeus:default/blocks/open_formspec")
dofile("zeus:default/blocks/sand")
dofile("zeus:default/blocks/sandstone")
dofile("zeus:default/blocks/stone")
dofile("zeus:default/blocks/tallgrass")
dofile("zeus:default/blocks/water")
dofile("zeus:default/blocks/wood")
runfile("zeus:default/blocks/bush_stem")
runfile("zeus:default/blocks/dirt")
runfile("zeus:default/blocks/grass")
runfile("zeus:default/blocks/leaves")
runfile("zeus:default/blocks/open_formspec")
runfile("zeus:default/blocks/sand")
runfile("zeus:default/blocks/sandstone")
runfile("zeus:default/blocks/stone")
runfile("zeus:default/blocks/tallgrass")
runfile("zeus:default/blocks/water")
runfile("zeus:default/blocks/wood")

View File

@ -1,4 +1,4 @@
zeus.register_block("default:bush_stem", {
zepha.register_block("default:bush_stem", {
visible = true,
culls = false,
name = "Bush Stem",

View File

@ -1,4 +1,4 @@
zeus.register_block("default:dirt", {
zepha.register_block("default:dirt", {
name = "Dirt",
model = "default:block",
textures = {"zeus:default:dirt"},

View File

@ -1,4 +1,4 @@
zeus.register_block("default:grass", {
zepha.register_block("default:grass", {
name = "Grass",
model = "default:block_foliage",
textures = {

View File

@ -1,4 +1,4 @@
zeus.register_block("default:leaves", {
zepha.register_block("default:leaves", {
visible = true,
culls = false,
name = "Leaves",

View File

@ -1,9 +1,9 @@
zeus.register_block("default:open_formspec", {
zepha.register_block("default:open_formspec", {
name = "Open Formspec Block",
model = "default:block",
textures = {"zeus:default:brick"},
on_place_client = function()
zeus.show_menu({
zepha.show_menu({
key = "form_root",
type = "rect",

View File

@ -1,4 +1,4 @@
zeus.register_block("default:sand", {
zepha.register_block("default:sand", {
name = "Sand",
model = "default:block",
textures = {"zeus:default:sand"},

View File

@ -1,13 +1,13 @@
local entities = {}
local function collides(entity)
return zeus.get_block({
return zepha.get_block({
x = math.floor(entity.pos.x),
y = math.floor(entity.pos.y - 0.5),
z = math.floor(entity.pos.z)}) ~= "air"
end
zeus.register_block("default:sandstone", {
zepha.register_block("default:sandstone", {
name = "Sandstone",
model = "default:block",
textures = {"zeus:default:sandstone"},
@ -23,7 +23,7 @@ zeus.register_block("default:sandstone", {
local velocityY = -3
local time = 0
zeus.delay(function()
zepha.delay(function()
entity.yaw = entity.yaw + speed
if speed > 10 then speed = speed * 0.8 end
@ -38,9 +38,12 @@ zeus.register_block("default:sandstone", {
entity.pos = {x = entity.pos.x, y = entity.pos.y + interval, z = entity.pos.z}
v = v + 0.25
end
if collides(entity) then
velocityY = 0
time = time + 1/20
end
entity.visual_offset = {x = 0, y = math.sin(time * 4) / 8, z = 0}
time = time + 1/20
return true
end, 1/20)

View File

@ -1,4 +1,4 @@
zeus.register_block("default:stone", {
zepha.register_block("default:stone", {
name = "Stone",
model = "default:block",
textures = {"zeus:default:stone"},

View File

@ -1,5 +1,5 @@
for i=1,5,1 do
zeus.register_block("default:tallgrass_" .. i, {
zepha.register_block("default:tallgrass_" .. i, {
culls = false,
solid = false,
name = "Tall Grass",

View File

@ -1,4 +1,4 @@
zeus.register_block("default:water", {
zepha.register_block("default:water", {
name = "Water",
model = "default:block",
textures = {"zeus:default:water"}

View File

@ -1,4 +1,4 @@
zeus.register_block("default:wood", {
zepha.register_block("default:wood", {
name = "Log",
model = "default:block",
textures = {

View File

@ -1 +1 @@
--dofile("zeus:default/items/stick")
--runfile("zeus:default/items/stick")

View File

@ -1,5 +1,5 @@
print("Hello from default")
dofile("zeus:default/models")
dofile("zeus:default/blocks")
dofile("zeus:default/items")
runfile("zeus:default/models")
runfile("zeus:default/blocks")
runfile("zeus:default/items")

View File

@ -1,7 +1,7 @@
dofile("zeus:default/models/block")
dofile("zeus:default/models/block_foliage")
dofile("zeus:default/models/plantlike")
dofile("zeus:default/models/leaflike")
dofile("zeus:default/models/halfslab")
dofile("zeus:default/models/halfslab_foliage")
dofile("zeus:default/models/crosslarge")
runfile("zeus:default/models/block")
runfile("zeus:default/models/block_foliage")
runfile("zeus:default/models/plantlike")
runfile("zeus:default/models/leaflike")
runfile("zeus:default/models/halfslab")
runfile("zeus:default/models/halfslab_foliage")
runfile("zeus:default/models/crosslarge")

View File

@ -3,7 +3,7 @@
-- Texture order is: top, bottom, left, right, front, back.
--
zeus.register_blockmodel("default:block", {
zepha.register_blockmodel("default:block", {
parts = {
{
face = "left",

View File

@ -6,7 +6,7 @@
local amp = 0.1
zeus.register_blockmodel("default:block_foliage", {
zepha.register_blockmodel("default:block_foliage", {
parts = {
{
face = "left",

View File

@ -4,7 +4,7 @@
-- Only takes one texture, which is displayed on all faces.
--
zeus.register_blockmodel("default:crosslarge", {
zepha.register_blockmodel("default:crosslarge", {
parts = {
{
face = "nocull",

View File

@ -3,7 +3,7 @@
-- Texture order is: top, bottom, left, right, front, back.
--
zeus.register_blockmodel("default:halfslab", {
zepha.register_blockmodel("default:halfslab", {
parts = {
{
face = "left",

View File

@ -3,7 +3,7 @@
-- Texture order is: top, bottom, left, right, front, back.
--
zeus.register_blockmodel("default:halfslab_foliage", {
zepha.register_blockmodel("default:halfslab_foliage", {
parts = {
{
face = "left",

View File

@ -6,7 +6,7 @@
local amp = 0.2
zeus.register_blockmodel("default:leaflike", {
zepha.register_blockmodel("default:leaflike", {
parts = {
{
face = "left",

View File

@ -7,7 +7,7 @@
local wave_amplitude = 0.6
local offset_amplitude = 0.3
zeus.register_blockmodel("default:plantlike", {
zepha.register_blockmodel("default:plantlike", {
mesh_mods = {
{
type = "offset_x",

View File

@ -16,7 +16,7 @@ end
for _,flower in ipairs(flowers) do
local name = flower:gsub("_", " "):gsub("(%a)([%w_']*)", tchelper)
zeus.register_block("flowers:flower_" .. flower, {
zepha.register_block("flowers:flower_" .. flower, {
culls = false,
solid = false,
name = name,

View File

@ -1,3 +1,3 @@
print("Hello from flowers")
dofile("zeus:flowers/flowers")
runfile("zeus:flowers/flowers")

View File

@ -1,4 +1,4 @@
zeus.register_block('kinetic:axle_0', {
zepha.register_block('kinetic:axle_0', {
name = "Axle",
model = "kinetic:axle_0",
textures = {"zeus:kinetic:axle"},
@ -9,23 +9,23 @@ zeus.register_block('kinetic:axle_0', {
on_place = function(pos)
for i = 0, 9 do
pos.x = pos.x + 1
zeus.set_block(pos, "kinetic:axle_0")
zepha.set_block(pos, "kinetic:axle_0")
end
end,
on_place_client = function(pos)
for i = 0, 9 do
pos.x = pos.x + 1
zeus.set_block(pos, "kinetic:axle_0")
zepha.set_block(pos, "kinetic:axle_0")
end
end,
on_construct = function(pos)
zeus.delay(function()
zeus.set_block(pos, "kinetic:axle_1")
zepha.delay(function()
zepha.set_block(pos, "kinetic:axle_1")
end, 4)
end
})
zeus.register_block('kinetic:axle_1', {
zepha.register_block('kinetic:axle_1', {
name = "Axle",
model = "kinetic:axle_1",
textures = {"zeus:kinetic:axle"},
@ -34,13 +34,13 @@ zeus.register_block('kinetic:axle_1', {
{0, 6/16, 6/16, 1, 10/16, 10/16}
},
on_construct = function(pos)
zeus.delay(function()
zeus.set_block(pos, "kinetic:axle_2")
zepha.delay(function()
zepha.set_block(pos, "kinetic:axle_2")
end, 4)
end
})
zeus.register_block('kinetic:axle_2', {
zepha.register_block('kinetic:axle_2', {
name = "Axle",
model = "kinetic:axle_2",
textures = {"zeus:kinetic:axle"},
@ -49,13 +49,13 @@ zeus.register_block('kinetic:axle_2', {
{0, 6/16, 6/16, 1, 10/16, 10/16}
},
on_construct = function(pos)
zeus.delay(function()
zeus.set_block(pos, "kinetic:axle_3")
zepha.delay(function()
zepha.set_block(pos, "kinetic:axle_3")
end, 4)
end
})
zeus.register_block('kinetic:axle_3', {
zepha.register_block('kinetic:axle_3', {
name = "Axle",
model = "kinetic:axle_3",
textures = {"zeus:kinetic:axle"},
@ -64,8 +64,8 @@ zeus.register_block('kinetic:axle_3', {
{0, 6/16, 6/16, 1, 10/16, 10/16}
},
on_construct = function(pos)
zeus.delay(function()
zeus.set_block(pos, "kinetic:axle_0")
zepha.delay(function()
zepha.set_block(pos, "kinetic:axle_0")
end, 4)
end
})

View File

@ -1,4 +1,4 @@
print("Hello from kinetic")
dofile("zeus:kinetic/models/axle")
dofile("zeus:kinetic/blocks/axle")
runfile("zeus:kinetic/models/axle")
runfile("zeus:kinetic/blocks/axle")

View File

@ -87,7 +87,7 @@ local function create_model_def(speed)
}
end
zeus.register_blockmodel("kinetic:axle_0", create_model_def(0));
zeus.register_blockmodel("kinetic:axle_1", create_model_def(0.5));
zeus.register_blockmodel("kinetic:axle_2", create_model_def(1));
zeus.register_blockmodel("kinetic:axle_3", create_model_def(2));
zepha.register_blockmodel("kinetic:axle_0", create_model_def(0));
zepha.register_blockmodel("kinetic:axle_1", create_model_def(0.5));
zepha.register_blockmodel("kinetic:axle_2", create_model_def(1));
zepha.register_blockmodel("kinetic:axle_3", create_model_def(2));

View File

@ -1,4 +1,4 @@
--zeus.register_item("materials:stick", {
--zepha.register_item("materials:stick", {
-- name = "Stick",
-- groups = {
-- stick = 1,

View File

@ -1,3 +1,3 @@
print("Hello from materials")
dofile("zeus:materials/items/stick")
runfile("zeus:materials/items/stick")

View File

@ -219,7 +219,7 @@ TextureAtlas::RawTexData TextureAtlas::getSubImageBytes(std::string &name) {
std::shared_ptr<AtlasRef> TextureAtlas::generateCrackImage(std::string &name, unsigned short crackLevel) {
RawTexData base = getSubImageBytes(name);
std::string crackStr("zeus:default:crack_" + std::to_string(crackLevel));
std::string crackStr("zepha:default:crack_" + std::to_string(crackLevel));
RawTexData crack = getSubImageBytes(crackStr);
for (int i = 0; i < base.width * base.height; i++) {

View File

@ -20,7 +20,7 @@ void Entity::setModel(std::shared_ptr<Model> model) {
void Entity::update(double delta) {
animState.update(delta);
float factor = static_cast<float>(fmin(delta * 15, 1));
float factor = static_cast<float>(fmin(delta * 10, 1));
visualPosition = visualPosition * (1 - factor) + position * factor;
visualVisualOffset = visualVisualOffset * (1 - factor) + visualOffset * factor;

View File

@ -34,7 +34,7 @@ public:
sol::table vecToTable(glm::vec3 vec);
sol::state lua;
sol::table zeus;
sol::table core;
std::list<DelayedFunction> delayed_functions;
};

View File

@ -8,8 +8,8 @@
#include <sol2/sol.hpp>
namespace ClientApi {
void delay(sol::table &zeus, std::list<LocalLuaParser::DelayedFunction> &funcs) {
zeus.set_function("delay", [&](sol::function function, float delay, sol::variadic_args args) {
void delay(sol::table &core, std::list<LocalLuaParser::DelayedFunction> &funcs) {
core.set_function("delay", [&](sol::function function, float delay, sol::variadic_args args) {
std::vector<sol::object> argsObject;
for (auto arg : args) argsObject.push_back(arg);
funcs.push_back({function, argsObject, delay, delay});

View File

@ -9,8 +9,8 @@
#include <sol2/sol.hpp>
namespace ClientApi {
void get_block(sol::table &zeus, LocalDefs& defs, LocalWorld& world) {
zeus.set_function("get_block", [&](sol::table pos) -> std::string {
void get_block(sol::table &core, LocalDefs& defs, LocalWorld& world) {
core.set_function("get_block", [&](sol::table pos) -> std::string {
if (!pos["x"] || !pos["y"] || !pos["z"]) {
std::cout << Log::err << "get_block vector is ill formed." << Log::endl;
return "";

View File

@ -7,8 +7,8 @@
#include <sol2/sol.hpp>
namespace ClientApi {
void is_server(sol::table& zeus) {
zeus.set_function("is_server", []() {
void is_server(sol::table& core) {
core.set_function("is_server", []() {
return false;
});
}

View File

@ -7,12 +7,12 @@
#include <sol2/sol.hpp>
namespace ClientApi {
void register_block(sol::state& lua, sol::table& zeus) {
zeus["registered_blocks"] = lua.create_table();
void register_block(sol::state& lua, sol::table& core) {
core["registered_blocks"] = lua.create_table();
zeus.set_function("register_block", [&](std::string identifier, sol::table data) {
core.set_function("register_block", [&](std::string identifier, sol::table data) {
if (identifier.length() == 0) throw "Missing Identifier";
zeus["registered_blocks"][identifier] = data;
core["registered_blocks"][identifier] = data;
});
}
}

View File

@ -7,12 +7,12 @@
#include <sol2/sol.hpp>
namespace ClientApi {
void register_blockmodel(sol::state& lua, sol::table& zeus) {
zeus["registered_blockmodels"] = lua.create_table();
void register_blockmodel(sol::state& lua, sol::table& core) {
core["registered_blockmodels"] = lua.create_table();
zeus.set_function("register_blockmodel", [&](std::string identifier, sol::table data) {
core.set_function("register_blockmodel", [&](std::string identifier, sol::table data) {
if (identifier.length() == 0) throw "Missing Identifier";
zeus["registered_blockmodels"][identifier] = data;
core["registered_blockmodels"][identifier] = data;
});
}
}

View File

@ -7,12 +7,12 @@
#include <sol2/sol.hpp>
namespace ClientApi {
void register_item(sol::state& lua, sol::table& zeus) {
zeus["registered_items"] = lua.create_table();
void register_item(sol::state& lua, sol::table& core) {
core["registered_items"] = lua.create_table();
zeus.set_function("register_item", [&](std::string identifier, sol::table data) {
core.set_function("register_item", [&](std::string identifier, sol::table data) {
if (identifier.length() == 0) throw "Missing Identifier";
zeus["registered_items"][identifier] = data;
core["registered_items"][identifier] = data;
});
}
}

View File

@ -9,8 +9,8 @@
#include <sol2/sol.hpp>
namespace ClientApi {
void remove_block(sol::table &zeus, LocalDefs& defs, LocalWorld& world) {
zeus.set_function("remove_block", [&](sol::table pos) {
void remove_block(sol::table &core, LocalDefs& defs, LocalWorld& world) {
core.set_function("remove_block", [&](sol::table pos) {
if (!pos["x"] || !pos["y"] || !pos["z"]) {
std::cout << Log::err << "remove_block vector is ill formed." << Log::endl;
return;

View File

@ -9,8 +9,8 @@
#include <sol2/sol.hpp>
namespace ClientApi {
void set_block(sol::table &zeus, LocalDefs& defs, LocalWorld& world) {
zeus.set_function("set_block", [&](sol::table pos, std::string identifier) {
void set_block(sol::table &core, LocalDefs& defs, LocalWorld& world) {
core.set_function("set_block", [&](sol::table pos, std::string identifier) {
if (!pos["x"] || !pos["y"] || !pos["z"]) {
std::cout << Log::err << "set_block vector is ill formed." << Log::endl;
return;

View File

@ -136,9 +136,9 @@ void processElement(LocalDefs& defs, sol::table& element, std::shared_ptr<GUICom
}
namespace ClientApi {
void show_menu(sol::table &zeus, LocalDefs& defs, GameGui& gui) {
void show_menu(sol::table &core, LocalDefs& defs, GameGui& gui) {
zeus.set_function("show_menu", [&](sol::table gui_root) {
core.set_function("show_menu", [&](sol::table gui_root) {
auto root = std::make_shared<GUIContainer>("root");
gui.add(root);

View File

@ -8,8 +8,8 @@
#include <sol2/sol.hpp>
namespace ServerApi {
void delay(sol::table &zeus, std::list<ServerLuaParser::DelayedFunction> &funcs) {
zeus.set_function("delay", [&](sol::function function, float delay, sol::variadic_args args) {
void delay(sol::table &core, std::list<ServerLuaParser::DelayedFunction> &funcs) {
core.set_function("delay", [&](sol::function function, float delay, sol::variadic_args args) {
std::vector<sol::object> argsObject;
for (auto arg : args) argsObject.push_back(arg);
funcs.push_back({function, argsObject, delay, delay});

View File

@ -9,8 +9,8 @@
#include <sol2/sol.hpp>
namespace ServerApi {
void get_block(sol::table &zeus, ServerDefs& defs, ServerWorld& world) {
zeus.set_function("get_block", [&](sol::table pos) -> std::string {
void get_block(sol::table &core, ServerDefs& defs, ServerWorld& world) {
core.set_function("get_block", [&](sol::table pos) -> std::string {
if (!pos["x"] || !pos["y"] || !pos["z"]) {
std::cout << Log::err << "get_block vector is ill formed." << Log::endl;
return "";

View File

@ -7,8 +7,8 @@
#include <sol2/sol.hpp>
namespace ServerApi {
void is_server(sol::table& zeus) {
zeus.set_function("is_server", []() {
void is_server(sol::table& core) {
core.set_function("is_server", []() {
return true;
});
}

View File

@ -7,12 +7,12 @@
#include <sol2/sol.hpp>
namespace ServerApi {
void register_block(sol::state& lua, sol::table& zeus) {
zeus["registered_blocks"] = lua.create_table();
void register_block(sol::state& lua, sol::table& core) {
core["registered_blocks"] = lua.create_table();
zeus.set_function("register_block", [&](std::string identifier, sol::table data) {
core.set_function("register_block", [&](std::string identifier, sol::table data) {
if (identifier.length() == 0) throw "Missing Identifier";
zeus["registered_blocks"][identifier] = data;
core["registered_blocks"][identifier] = data;
});
}
}

View File

@ -7,12 +7,12 @@
#include <sol2/sol.hpp>
namespace ServerApi {
void register_blockmodel(sol::state& lua, sol::table& zeus) {
zeus["registered_blockmodels"] = lua.create_table();
void register_blockmodel(sol::state& lua, sol::table& core) {
core["registered_blockmodels"] = lua.create_table();
zeus.set_function("register_blockmodel", [&](std::string identifier, sol::table data) {
core.set_function("register_blockmodel", [&](std::string identifier, sol::table data) {
if (identifier.length() == 0) throw "Missing Identifier";
zeus["registered_blockmodels"][identifier] = data;
core["registered_blockmodels"][identifier] = data;
});
}
}

View File

@ -7,12 +7,12 @@
#include <sol2/sol.hpp>
namespace ServerApi {
void register_item(sol::state& lua, sol::table& zeus) {
zeus["registered_items"] = lua.create_table();
void register_item(sol::state& lua, sol::table& core) {
core["registered_items"] = lua.create_table();
zeus.set_function("register_item", [&](std::string identifier, sol::table data) {
core.set_function("register_item", [&](std::string identifier, sol::table data) {
if (identifier.length() == 0) throw "Missing Identifier";
zeus["registered_items"][identifier] = data;
core["registered_items"][identifier] = data;
});
}
}

View File

@ -9,8 +9,8 @@
#include <sol2/sol.hpp>
namespace ServerApi {
void remove_block(sol::table &zeus, ServerDefs& defs, ServerWorld& world) {
zeus.set_function("remove_block", [&](sol::table pos) {
void remove_block(sol::table &core, ServerDefs& defs, ServerWorld& world) {
core.set_function("remove_block", [&](sol::table pos) {
if (!pos["x"] || !pos["y"] || !pos["z"]) {
std::cout << Log::err << "remove_block vector is ill formed." << Log::endl;
return;

View File

@ -9,8 +9,8 @@
#include <sol2/sol.hpp>
namespace ServerApi {
void set_block(sol::table &zeus, ServerDefs& defs, ServerWorld& world) {
zeus.set_function("set_block", [&](sol::table pos, std::string identifier) {
void set_block(sol::table &core, ServerDefs& defs, ServerWorld& world) {
core.set_function("set_block", [&](sol::table pos, std::string identifier) {
if (!pos["x"] || !pos["y"] || !pos["z"]) {
std::cout << Log::err << "set_block vector is ill formed." << Log::endl;
return;

View File

@ -50,7 +50,7 @@ namespace ClientApi {
}
};
void entity(sol::state& lua, sol::table &zeus, LocalDefs& defs, LocalWorld& world) {
void entity(sol::state& lua, sol::table &core, LocalDefs& defs, LocalWorld& world) {
lua.new_usertype<LuaEntity>(
"LuaEntity",
"new", sol::factories([&world, &defs, &lua](sol::table pos){

View File

@ -42,31 +42,32 @@ void LocalLuaParser::init(LocalDefs& defs, LocalWorld& world, GameGui& gui) {
}
void LocalLuaParser::loadModules(LocalDefs &defs, LocalWorld &world, GameGui& gui) {
//Create Zeus Table
zeus = lua.create_table();
lua["zeus"] = zeus;
//Create Zepha Table
core = lua.create_table();
lua["zepha"] = core;
//Load Types
ClientApi::entity(lua, zeus, defs, world);
ClientApi::entity(lua, core, defs, world);
//Load Modules
ClientApi::dump(lua);
ClientApi::printe(lua);
ClientApi::is_server(zeus);
ClientApi::delay(zeus, delayed_functions);
ClientApi::is_server(core);
ClientApi::delay(core, delayed_functions);
ClientApi::register_block(lua, zeus);
ClientApi::register_blockmodel(lua, zeus);
ClientApi::register_block(lua, core);
ClientApi::register_blockmodel(lua, core);
ClientApi::get_block(zeus, defs, world);
ClientApi::set_block(zeus, defs, world);
ClientApi::remove_block(zeus, defs, world);
ClientApi::get_block(core, defs, world);
ClientApi::set_block(core, defs, world);
ClientApi::remove_block(core, defs, world);
ClientApi::show_menu(zeus, defs, gui);
ClientApi::show_menu(core, defs, gui);
//Sandbox the dofile function
lua.set_function("dofile", &LocalLuaParser::DoFileSandboxed, this);
lua["dofile"] = sol::nil;
lua.set_function("runfile", &LocalLuaParser::DoFileSandboxed, this);
}
void LocalLuaParser::loadMods() {
@ -76,10 +77,10 @@ void LocalLuaParser::loadMods() {
}
void LocalLuaParser::registerBlocks(LocalDefs& defs) {
LocalRegisterBlocks(zeus, defs);
LocalRegisterBlocks(core, defs);
}
int LocalLuaParser::DoFileSandboxed(std::string file) {
sol::protected_function_result LocalLuaParser::DoFileSandboxed(std::string file) {
size_t modname_length = file.find('/');
std::string modname = file.substr(0, modname_length);
@ -87,13 +88,17 @@ int LocalLuaParser::DoFileSandboxed(std::string file) {
if (strncmp(mod.config.name.c_str(), modname.c_str(), modname_length) == 0) {
for (LuaModFile& f : mod.files) {
if (f.path == file) {
lua.safe_script(f.file);
return 0;
auto pfr = lua.safe_script(f.file, [](lua_State*, sol::protected_function_result errPfr) {
sol::error err = errPfr;
std::cout << Log::err << "DoFileSandboxed returned an error: " << err.what() << Log::endl;
return errPfr;
});
return pfr;
}
}
// TODO: No file found by that name - throw error?
std::cout << Log::err << "Error opening \"" + file + "\", not found." << Log::endl;
break;
}
}
std::cout << Log::err << "Error opening \"" + file + "\", not found." << Log::endl;
}

View File

@ -25,5 +25,5 @@ public:
std::vector<LuaMod> mods;
std::vector<std::string> modsOrder;
private:
int DoFileSandboxed(std::string file);
sol::protected_function_result DoFileSandboxed(std::string file);
};

View File

@ -4,9 +4,9 @@
#include "LocalRegisterBlocks.h"
LocalRegisterBlocks::LocalRegisterBlocks(sol::table& zeus, LocalDefs &defs) {
//Register all of the blocks in the zeus.registered_blocks table.
for (auto blockRef : zeus.get<sol::table>("registered_blocks")) {
LocalRegisterBlocks::LocalRegisterBlocks(sol::table& core, LocalDefs &defs) {
//Register all of the blocks in the zepha.registered_blocks table.
for (auto blockRef : core.get<sol::table>("registered_blocks")) {
//Get the unique identifier of the block
std::string identifier = blockRef.first.as<std::string>();
@ -28,9 +28,9 @@ LocalRegisterBlocks::LocalRegisterBlocks(sol::table& zeus, LocalDefs &defs) {
bool culls = blockTable.get_or("culls", true);
bool solid = blockTable.get_or("solid", true);
//Get the identifier for the blockModel, and then get the model from the zeus.registered_blockmodels table.
//Get the identifier for the blockModel, and then get the model from the zepha.registered_blockmodels table.
std::string modelStr = (modelStrOpt ? *modelStrOpt : "default:cube");
sol::optional<sol::table> modelOpt = zeus.get<sol::table>("registered_blockmodels").get<sol::table>(modelStr);
sol::optional<sol::table> modelOpt = core.get<sol::table>("registered_blockmodels").get<sol::table>(modelStr);
if (!modelOpt) throw identifier + " specifies invalid model " + modelStr + "!";
//Create a vector of selection boxes

View File

@ -10,6 +10,6 @@
class LocalRegisterBlocks {
public:
LocalRegisterBlocks(sol::table& zeus, LocalDefs& defs);
LocalRegisterBlocks(sol::table& core, LocalDefs& defs);
};

View File

@ -39,30 +39,31 @@ void ServerLuaParser::init(ServerDefs& defs, ServerWorld& world, std::string pat
}
void ServerLuaParser::loadModules(ServerDefs &defs, ServerWorld &world) {
//Create Zeus Table
zeus = lua.create_table();
lua["zeus"] = zeus;
//Create Zepha Table
core = lua.create_table();
lua["zepha"] = core;
//Load Modules
ServerApi::dump(lua);
ServerApi::printe(lua);
ServerApi::is_server(zeus);
ServerApi::delay(zeus, delayed_functions);
ServerApi::is_server(core);
ServerApi::delay(core, delayed_functions);
ServerApi::register_block(lua, zeus);
ServerApi::register_blockmodel(lua, zeus);
ServerApi::register_block(lua, core);
ServerApi::register_blockmodel(lua, core);
ServerApi::get_block(zeus, defs, world);
ServerApi::set_block(zeus, defs, world);
ServerApi::remove_block(zeus, defs, world);
ServerApi::get_block(core, defs, world);
ServerApi::set_block(core, defs, world);
ServerApi::remove_block(core, defs, world);
//Sandbox the dofile function
lua.set_function("dofile", &ServerLuaParser::DoFileSandboxed, this);
lua["dofile"] = sol::nil;
lua.set_function("runfile", &ServerLuaParser::DoFileSandboxed, this);
}
void ServerLuaParser::registerBlocks(ServerDefs& defs) {
ServerRegisterBlocks(zeus, defs);
ServerRegisterBlocks(core, defs);
}
void ServerLuaParser::loadMods(ServerDefs& defs, const std::string& rootPath) {
@ -248,8 +249,6 @@ void ServerLuaParser::createTextures(ServerDefs &defs) {
cf_dir_close(&dir);
}
}
}
void ServerLuaParser::handleDependencies() {
@ -307,8 +306,7 @@ void ServerLuaParser::serializeMods() {
}
}
int ServerLuaParser::DoFileSandboxed(std::string file) {
sol::protected_function_result ServerLuaParser::DoFileSandboxed(std::string file) {
size_t modname_length = file.find('/');
std::string modname = file.substr(0, modname_length);
@ -316,13 +314,17 @@ int ServerLuaParser::DoFileSandboxed(std::string file) {
if (strncmp(mod.config.name.c_str(), modname.c_str(), modname_length) == 0) {
for (LuaModFile& f : mod.files) {
if (f.path == file) {
lua.safe_script(f.file);
return 0;
auto pfr = lua.safe_script(f.file, [](lua_State*, sol::protected_function_result errPfr) {
sol::error err = errPfr;
std::cout << Log::err << "DoFileSandboxed returned an error: " << err.what() << Log::endl;
return errPfr;
});
return pfr;
}
}
// TODO: No file found by that name - throw error?
std::cout << Log::err << "Error opening \"" + file + "\", not found." << Log::endl;
break;
}
}
std::cout << Log::err << "Error opening \"" + file + "\", not found." << Log::endl;
}

View File

@ -34,6 +34,6 @@ private:
void handleDependencies();
void serializeMods();
int DoFileSandboxed(std::string file);
sol::protected_function_result DoFileSandboxed(std::string file);
};

View File

@ -4,9 +4,9 @@
#include "ServerRegisterBlocks.h"
ServerRegisterBlocks::ServerRegisterBlocks(sol::table& zeus, ServerDefs &defs) {
//Register all of the blocks in the zeus.registered_blocks table.
for (auto blockRef : zeus.get<sol::table>("registered_blocks")) {
ServerRegisterBlocks::ServerRegisterBlocks(sol::table& core, ServerDefs &defs) {
//Register all of the blocks in the zepha.registered_blocks table.
for (auto blockRef : core.get<sol::table>("registered_blocks")) {
//Get the unique identifier of the block
std::string identifier = blockRef.first.as<std::string>();
@ -28,9 +28,9 @@ ServerRegisterBlocks::ServerRegisterBlocks(sol::table& zeus, ServerDefs &defs) {
bool culls = blockTable.get_or("culls", true);
bool solid = blockTable.get_or("solid", true);
//Get the identifier for the blockModel, and then get the model from the zeus.registered_blockmodels table.
//Get the identifier for the blockModel, and then get the model from the zepha.registered_blockmodels table.
std::string modelStr = (modelStrOpt ? *modelStrOpt : "default:cube");
sol::optional<sol::table> modelOpt = zeus.get<sol::table>("registered_blockmodels").get<sol::table>(modelStr);
sol::optional<sol::table> modelOpt = core.get<sol::table>("registered_blockmodels").get<sol::table>(modelStr);
if (!modelOpt) throw identifier + " specifies invalid model " + modelStr + "!";
//Create a vector of selection boxes

View File

@ -11,6 +11,6 @@
class ServerRegisterBlocks {
public:
ServerRegisterBlocks(sol::table& zeus, ServerDefs& defs);
ServerRegisterBlocks(sol::table& core, ServerDefs& defs);
};