Skip to content

Commit

Permalink
add some lua libraries to spel2.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Nov 9, 2023
1 parent fc8bf02 commit f3da9a4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
28 changes: 24 additions & 4 deletions docs/game_data/spel2.lua

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

27 changes: 23 additions & 4 deletions docs/generate_emmylua.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,36 @@ def main():
---@type any
options = nil
---@type PRNG
prng = nil"""
)
prng = nil
---Create a global `exports` table and put stuff in it,
---and other scripts will be able to `import` your script like a library
---@class Exports
---@type Exports
exports = nil
---The json library converts tables to json and json to tables
---Check https://github.com/rxi/json.lua for more information
---@class Json
---@field decode fun(str: string): table @Decode a json string into a table
---@field encode fun(tbl: table): string @Encode a table into a json string
---@type Json
json = nil
""")

print("\n-- Functions\n")
print(
"""
---Formatting function, use e.g. as f "my_var = {my_var}"
---Return any type of object or multiple objects as a debug string.
---@vararg any
---@return string
function inspect(...) end
---Formatting function, use e.g. as f"my_var = {my_var}"
---@param f_string string
---@return string
function f(f_string) end
---Formatting function, use e.g. as f "my_var = {my_var}"
---Formatting function, use e.g. as F"my_var = {my_var}"
---@param f_string string
---@return string
function F(f_string) end
Expand Down
2 changes: 1 addition & 1 deletion docs/src/includes/_globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ Grow vines from `GROWABLE_VINE` and `VINE_TREE_TOP` entities in a level, `area`

> Search script examples for [import](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=import)
#### table import(string id, string version = "", bool optional = false)
#### table import(string id, optional<string> version, optional<bool> optional)

Load another script by id "author/name" and import its `exports` table. Returns:

Expand Down
2 changes: 1 addition & 1 deletion src/game_api/script/lua_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ end
/// - `nil` if the script was found but has no exports
/// - `false` if the script was not found but optional is set to true
/// - an error if the script was not found and the optional argument was not set
// lua["import"] = [](string id, string version = "", bool optional = false) -> table
// lua["import"] = [](string id, optional<string> version, optional<bool> optional) -> table
lua["import"] = sol::overload(
[&lua](std::string id)
{
Expand Down

0 comments on commit f3da9a4

Please sign in to comment.