update lua chunks sources to the engine format
This commit is contained in:
@@ -144,7 +144,8 @@ State* lua::create_state(const EnginePaths& paths, StateType stateType) {
|
||||
init_state(L, stateType);
|
||||
|
||||
auto resDir = paths.getResourcesFolder();
|
||||
auto src = files::read_string(resDir / fs::u8path("scripts/stdmin.lua"));
|
||||
lua::pop(L, lua::execute(L, 0, src, "<stdmin>"));
|
||||
auto file = resDir / fs::u8path("scripts/stdmin.lua");
|
||||
auto src = files::read_string(file);
|
||||
lua::pop(L, lua::execute(L, 0, src, "core:scripts/stdmin.lua"));
|
||||
return L;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ void scripting::load_script(const fs::path& name, bool throwable) {
|
||||
fs::path file = paths->getResourcesFolder() / fs::path("scripts") / name;
|
||||
std::string src = files::read_string(file);
|
||||
auto L = lua::get_main_state();
|
||||
lua::loadbuffer(L, 0, src, file.u8string());
|
||||
lua::loadbuffer(L, 0, src, "core:scripts/"+name.u8string());
|
||||
if (throwable) {
|
||||
lua::call(L, 0, 0);
|
||||
} else {
|
||||
@@ -53,11 +53,14 @@ void scripting::load_script(const fs::path& name, bool throwable) {
|
||||
}
|
||||
|
||||
int scripting::load_script(
|
||||
int env, const std::string& type, const fs::path& file
|
||||
int env,
|
||||
const std::string& type,
|
||||
const fs::path& file,
|
||||
const std::string& fileName
|
||||
) {
|
||||
std::string src = files::read_string(file);
|
||||
logger.info() << "script (" << type << ") " << file.u8string();
|
||||
return lua::execute(lua::get_main_state(), env, src, file.u8string());
|
||||
return lua::execute(lua::get_main_state(), env, src, fileName);
|
||||
}
|
||||
|
||||
void scripting::initialize(Engine* engine) {
|
||||
@@ -657,10 +660,11 @@ void scripting::load_block_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const std::string& fileName,
|
||||
block_funcs_set& funcsset
|
||||
) {
|
||||
int env = *senv;
|
||||
lua::pop(lua::get_main_state(), load_script(env, "block", file));
|
||||
lua::pop(lua::get_main_state(), load_script(env, "block", file, fileName));
|
||||
funcsset.init = register_event(env, "init", prefix + ".init");
|
||||
funcsset.update = register_event(env, "on_update", prefix + ".update");
|
||||
funcsset.randupdate =
|
||||
@@ -677,10 +681,11 @@ void scripting::load_item_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const std::string& fileName,
|
||||
item_funcs_set& funcsset
|
||||
) {
|
||||
int env = *senv;
|
||||
lua::pop(lua::get_main_state(), load_script(env, "item", file));
|
||||
lua::pop(lua::get_main_state(), load_script(env, "item", file, fileName));
|
||||
funcsset.init = register_event(env, "init", prefix + ".init");
|
||||
funcsset.on_use = register_event(env, "on_use", prefix + ".use");
|
||||
funcsset.on_use_on_block =
|
||||
@@ -690,7 +695,7 @@ void scripting::load_item_script(
|
||||
}
|
||||
|
||||
void scripting::load_entity_component(
|
||||
const std::string& name, const fs::path& file
|
||||
const std::string& name, const fs::path& file, const std::string& fileName
|
||||
) {
|
||||
auto L = lua::get_main_state();
|
||||
std::string src = files::read_string(file);
|
||||
@@ -703,10 +708,11 @@ void scripting::load_world_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const std::string& fileName,
|
||||
world_funcs_set& funcsset
|
||||
) {
|
||||
int env = *senv;
|
||||
lua::pop(lua::get_main_state(), load_script(env, "world", file));
|
||||
lua::pop(lua::get_main_state(), load_script(env, "world", file, fileName));
|
||||
register_event(env, "init", prefix + ".init");
|
||||
register_event(env, "on_world_open", prefix + ":.worldopen");
|
||||
register_event(env, "on_world_tick", prefix + ":.worldtick");
|
||||
@@ -724,11 +730,12 @@ void scripting::load_layout_script(
|
||||
const scriptenv& senv,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const std::string& fileName,
|
||||
uidocscript& script
|
||||
) {
|
||||
int env = *senv;
|
||||
|
||||
lua::pop(lua::get_main_state(), load_script(env, "layout", file));
|
||||
lua::pop(lua::get_main_state(), load_script(env, "layout", file, fileName));
|
||||
script.onopen = register_event(env, "on_open", prefix + ".open");
|
||||
script.onprogress =
|
||||
register_event(env, "on_progress", prefix + ".progress");
|
||||
|
||||
@@ -125,11 +125,13 @@ namespace scripting {
|
||||
/// @param env environment
|
||||
/// @param prefix pack id
|
||||
/// @param file item script file
|
||||
/// @param fileName script file path using the engine format
|
||||
/// @param funcsset block callbacks set
|
||||
void load_block_script(
|
||||
const scriptenv& env,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const std::string& fileName,
|
||||
block_funcs_set& funcsset
|
||||
);
|
||||
|
||||
@@ -137,15 +139,25 @@ namespace scripting {
|
||||
/// @param env environment
|
||||
/// @param prefix pack id
|
||||
/// @param file item script file
|
||||
/// @param fileName script file path using the engine format
|
||||
/// @param funcsset item callbacks set
|
||||
void load_item_script(
|
||||
const scriptenv& env,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const std::string& fileName,
|
||||
item_funcs_set& funcsset
|
||||
);
|
||||
|
||||
void load_entity_component(const std::string& name, const fs::path& file);
|
||||
/// @brief Load component script
|
||||
/// @param name component full name (packid:name)
|
||||
/// @param file component script file path
|
||||
/// @param fileName script file path using the engine format
|
||||
void load_entity_component(
|
||||
const std::string& name,
|
||||
const fs::path& file,
|
||||
const std::string& fileName
|
||||
);
|
||||
|
||||
std::unique_ptr<GeneratorScript> load_generator(
|
||||
const GeneratorDef& def,
|
||||
@@ -157,10 +169,12 @@ namespace scripting {
|
||||
/// @param env environment
|
||||
/// @param packid content-pack id
|
||||
/// @param file script file path
|
||||
/// @param fileName script file path using the engine format
|
||||
void load_world_script(
|
||||
const scriptenv& env,
|
||||
const std::string& packid,
|
||||
const fs::path& file,
|
||||
const std::string& fileName,
|
||||
world_funcs_set& funcsset
|
||||
);
|
||||
|
||||
@@ -168,11 +182,13 @@ namespace scripting {
|
||||
/// @param env environment
|
||||
/// @param prefix pack id
|
||||
/// @param file item script file
|
||||
/// @param fileName script file path using the engine format
|
||||
/// @param script document script info
|
||||
void load_layout_script(
|
||||
const scriptenv& env,
|
||||
const std::string& prefix,
|
||||
const fs::path& file,
|
||||
const std::string& fileName,
|
||||
uidocscript& script
|
||||
);
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
namespace scripting {
|
||||
void load_script(const std::filesystem::path& name, bool throwable);
|
||||
|
||||
[[nodiscard]]
|
||||
int load_script(int env, const std::string& type, const std::filesystem::path& file);
|
||||
[[nodiscard]] int load_script(
|
||||
int env,
|
||||
const std::string& type,
|
||||
const std::filesystem::path& file,
|
||||
const std::string& fileName
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user