Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Oct 15, 2023
1 parent 8f6f1e4 commit 5df01ea
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
7 changes: 6 additions & 1 deletion docs/game_data/spel2.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions docs/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def print_lf(lf):

print("\n# Unsafe mode")
print(
"Setting `meta.unsafe = true` enables the rest of the standard Lua libraries like unrestricted `io` and `os`, loading dlls with require and `package.loadlib`. Using unsafe scripts requires users to enable the option in the overlunky.ini file which is found in the Spelunky 2 installation directory."
"Setting `meta.unsafe = true` enables the rest of the standard Lua libraries like unrestricted `io`, `os`, `ffi` and `debug`, loading dlls with require, `package.loadlib`, the [network functions](#Network-functions) and some [debug functions](#Debug-functions). Using unsafe scripts requires users to enable the option in the overlunky.ini file which is found in the Spelunky 2 installation directory."
)

print("\n# Modules")
Expand Down Expand Up @@ -393,7 +393,14 @@ def print_lf(lf):
cat = "Message functions"
elif any(
subs in func["name"]
for subs in ["get_rva", "get_virtual_rva", "raise", "dump_network"]
for subs in [
"get_rva",
"get_virtual_rva",
"raise",
"dump_network",
"dump",
"dump_string",
]
):
cat = "Debug functions"
elif any(subs in func["name"] for subs in ["_option"]):
Expand Down
11 changes: 10 additions & 1 deletion docs/src/includes/_globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ If you set such a callback and then play the same sound yourself you have to wai
## Debug functions


### dump


> Search script examples for [dump](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=dump)
#### table dump(object object, optional<int> depth)

Dump the object (table, container, class) as a recursive table, for pretty printing in console. Don't use this for anything except debug printing. Unsafe.

### dump_network


Expand Down Expand Up @@ -1983,7 +1992,7 @@ Prinspect to ingame console.
#### nil console_print(string message)

Print a log message to ingame console.
Print a log message to ingame console with a comment identifying the script that sent it.

### log_print

Expand Down
2 changes: 1 addition & 1 deletion docs/src/includes/_home.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ end
```

# Unsafe mode
Setting `meta.unsafe = true` enables the rest of the standard Lua libraries like unrestricted `io` and `os`, loading dlls with require and `package.loadlib`. Using unsafe scripts requires users to enable the option in the overlunky.ini file which is found in the Spelunky 2 installation directory.
Setting `meta.unsafe = true` enables the rest of the standard Lua libraries like unrestricted `io`, `os`, `ffi` and `debug`, loading dlls with require, `package.loadlib`, the [network functions](#Network-functions) and some [debug functions](#Debug-functions). Using unsafe scripts requires users to enable the option in the overlunky.ini file which is found in the Spelunky 2 installation directory.

# Modules
You can load modules with `require "mymod"` or `require "mydir.mymod"`, just put `mymod.lua` in the same directory the script is, or in `mydir/` to keep things organized.
Expand Down
9 changes: 5 additions & 4 deletions src/game_api/script/lua_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ end
/// Same as `print`
lua["message"] = [&lua](std::string message) -> void
{ lua["print"](message); };

/// Prints any type of object by first funneling it through `inspect`, no need for a manual `tostring` or `inspect`.
lua["prinspect"] = [&lua](sol::variadic_args objects) -> void
{
Expand All @@ -430,10 +431,14 @@ end
lua["print"](std::move(message));
}
};

/// Same as `prinspect`
lua["messpect"] = [&lua](sol::variadic_args objects) -> void
{ lua["prinspect"](objects); };

/// Dump the object (table, container, class) as a recursive table, for pretty printing in console. Don't use this for anything except debug printing. Unsafe.
// lua["dump"] = [](object object, optional<int> depth) -> table

/// Adds a command that can be used in the console.
lua["register_console_command"] = [](std::string name, sol::function cmd)
{
Expand Down Expand Up @@ -2780,7 +2785,6 @@ void add_partial_safe_libraries(sol::environment& env)
std::string fullpath = datadir + "/" + filename;
std::string dirpath = std::filesystem::path(fullpath).parent_path().string();
auto is_based = check_safe_io_path(fullpath, datadir);
DEBUG("io.open_data: safe:{} pack:{} based:{} mode:{} {}", is_safe, is_pack, is_based, mode.value_or("r"), fullpath);
if (is_safe && !is_based)
{
luaL_error(global_vm, "Attempted to open data file outside data directory");
Expand All @@ -2799,7 +2803,6 @@ void add_partial_safe_libraries(sol::environment& env)
std::string fullpath = std::string(backend->get_root()) + "/" + filename;
auto is_based = check_safe_io_path(fullpath, backend->get_root());
std::string dirpath = std::filesystem::path(fullpath).parent_path().string();
DEBUG("io.open_mod: safe:{} pack:{} based:{} mode:{} {}", is_safe, is_pack, is_based, mode.value_or("r"), fullpath);
if (is_safe)
{
if (!is_based)
Expand Down Expand Up @@ -2829,7 +2832,6 @@ void add_partial_safe_libraries(sol::environment& env)
std::string fullpath = datadir + "/" + filename;
std::string dirpath = std::filesystem::path(fullpath).parent_path().string();
auto is_based = check_safe_io_path(fullpath, datadir);
DEBUG("os.remove_data: safe:{} pack:{} based:{} {}", is_safe, is_pack, is_based, fullpath);
if (is_safe && !is_based)
{
luaL_error(global_vm, "Attempted to remove data file outside data directory");
Expand All @@ -2846,7 +2848,6 @@ void add_partial_safe_libraries(sol::environment& env)
std::string fullpath = std::string(backend->get_root()) + "/" + filename;
auto is_based = check_safe_io_path(fullpath, backend->get_root());
std::string dirpath = std::filesystem::path(fullpath).parent_path().string();
DEBUG("os.remove_mod: safe:{} pack:{} based:{} {}", is_safe, is_pack, is_based, fullpath);
if (is_safe)
{
if (!is_based)
Expand Down

0 comments on commit 5df01ea

Please sign in to comment.