From a89ab964385ad7520fb2950fcd32e4bb3c08107e Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Wed, 21 Jan 2026 14:32:41 +0100 Subject: [PATCH] Expose _G global variable in Space Lua --- client/space_lua/stdlib.ts | 2 ++ libraries/Library/Std/Editor/Lua.md | 13 +++++-------- website/Space Lua.md | 1 - 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/client/space_lua/stdlib.ts b/client/space_lua/stdlib.ts index 00b142bd..a7c4d677 100644 --- a/client/space_lua/stdlib.ts +++ b/client/space_lua/stdlib.ts @@ -359,6 +359,8 @@ const loadFunction = new LuaBuiltinFunction((sf, s) => luaLoad(s, sf)); export function luaBuildStandardEnv() { const env = new LuaEnv(); + // _G global + env.set("_G", env); // Top-level builtins env.set("print", printFunction); env.set("assert", assertFunction); diff --git a/libraries/Library/Std/Editor/Lua.md b/libraries/Library/Std/Editor/Lua.md index 68661b17..8bad9806 100644 --- a/libraries/Library/Std/Editor/Lua.md +++ b/libraries/Library/Std/Editor/Lua.md @@ -64,7 +64,7 @@ event.listen { end -- Split propaccess and traverse local propParts = string.split(propaccessPrefix[1], ".") - local currentValue = _CTX._GLOBAL + local currentValue = _G local failed = false for i = 1, #propParts-1 do local prop = propParts[i] @@ -175,7 +175,7 @@ event.listen { end local callText = text:sub(startPos+1, endPos-1) local propParts = callText:split(".") - local currentValue = _CTX._GLOBAL + local currentValue = _G for i = 1, #propParts do local prop = propParts[i] if currentValue then @@ -190,12 +190,9 @@ event.listen { -- Parse out the position in the doc local refBits = ctx.ref:split("@") -- Navigate there - editor.navigate({ - kind="page", - page=refBits[1], - -- Has to be offset a bit - pos=tonumber(refBits[2]) + ctx.from + #"```space-lua\n" - }) + editor.navigate(refBits[1] .. "@" .. + (tonumber(refBits[2]) + ctx.from + #"```space-lua\n") + ) else return notDefinedinLua() end diff --git a/website/Space Lua.md b/website/Space Lua.md index 126630cb..5dbc6158 100644 --- a/website/Space Lua.md +++ b/website/Space Lua.md @@ -161,7 +161,6 @@ Space Lua introduces a few new features on top core Lua: There's a magic `_CTX` global variable available from which you can access useful context-specific values. Currently the following keys are available: * `_CTX.currentPage` providing access (in the client only) to the currently open page (PageMeta object) -* `_CTX._GLOBAL` providing access to the global scope # API ![[API]]