From 388e54b3e399cc0a45e4353f0658d5328bb75ee5 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Thu, 21 Aug 2025 22:31:37 +0200 Subject: [PATCH] Add comprehensive help string for available Lua functions --- main.go | 2 ++ processor/processor.go | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/main.go b/main.go index 99d7cfe..af98284 100644 --- a/main.go +++ b/main.go @@ -58,6 +58,8 @@ func main() { fmt.Fprintf(os.Stderr, " If expression starts with an operator like *, /, +, -, =, etc., v1 is automatically prepended\n") fmt.Fprintf(os.Stderr, " You can use any valid Lua code, including if statements, loops, etc.\n") fmt.Fprintf(os.Stderr, " Glob patterns are supported for file selection (*.xml, data/**.xml, etc.)\n") + fmt.Fprintf(os.Stderr, "\nLua Functions Available:\n") + fmt.Fprintf(os.Stderr, "%s\n", processor.GetLuaFunctionsHelp()) } // TODO: Fix bed shitting when doing *.yml in barotrauma directory flag.Parse() diff --git a/processor/processor.go b/processor/processor.go index 3b7ab73..603eec5 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -502,3 +502,51 @@ func evalRegex(L *lua.LState) int { return 0 } + +// GetLuaFunctionsHelp returns a comprehensive help string for all available Lua functions +func GetLuaFunctionsHelp() string { + return `Lua Functions Available in Global Environment: + +MATH FUNCTIONS: + min(a, b) - Returns the minimum of two numbers + max(a, b) - Returns the maximum of two numbers + round(x, n) - Rounds x to n decimal places (default 0) + floor(x) - Returns the floor of x + ceil(x) - Returns the ceiling of x + +STRING FUNCTIONS: + upper(s) - Converts string to uppercase + lower(s) - Converts string to lowercase + format(s, ...) - Formats string using Lua string.format + trim(s) - Removes leading/trailing whitespace + strsplit(inputstr, sep) - Splits string by separator (default: whitespace) + num(str) - Converts string to number (returns 0 if invalid) + str(num) - Converts number to string + is_number(str) - Returns true if string is numeric + +TABLE FUNCTIONS: + DumpTable(table, depth) - Prints table structure recursively + isArray(t) - Returns true if table is a sequential array + +HTTP FUNCTIONS: + fetch(url, options) - Makes HTTP request, returns response table + options: {method="GET", headers={}, body=""} + returns: {status, statusText, ok, body, headers} + +REGEX FUNCTIONS: + re(pattern, input) - Applies regex pattern to input string + returns: table with matches (index 0 = full match, 1+ = groups) + +UTILITY FUNCTIONS: + print(...) - Prints arguments to Go logger + +EXAMPLES: + round(3.14159, 2) -> 3.14 + strsplit("a,b,c", ",") -> {"a", "b", "c"} + upper("hello") -> "HELLO" + min(5, 3) -> 3 + num("123") -> 123 + is_number("abc") -> false + fetch("https://api.example.com/data") + re("(\\w+)@(\\w+)", "user@domain.com") -> {"user@domain.com", "user", "domain.com"}` +}