From fb7be2a45a0069a50dfeb62ff40c3a5692e8e85f Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Sun, 9 Feb 2025 18:37:21 +0100 Subject: [PATCH] Changelog updates and Lua fixes --- common/space_lua/stdlib/string.ts | 4 ++-- common/space_lua/stdlib/string_test.lua | 8 ++++---- lib/plugos/syscalls/datastore.ts | 6 +++++- plugs/core/Library/Std/Lua.md | 4 ++-- website/API.md | 2 +- website/API/string.md | 14 ++++++++------ website/CHANGELOG.md | 17 ++++++++++++++++- website/Library/Std.md | 6 ++++++ 8 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 website/Library/Std.md diff --git a/common/space_lua/stdlib/string.ts b/common/space_lua/stdlib/string.ts index c3333d22..b159d44b 100644 --- a/common/space_lua/stdlib/string.ts +++ b/common/space_lua/stdlib/string.ts @@ -198,10 +198,10 @@ export const stringApi = new LuaTable({ }), // Non-standard - startswith: new LuaBuiltinFunction((_sf, s: string, prefix: string) => { + startsWith: new LuaBuiltinFunction((_sf, s: string, prefix: string) => { return s.startsWith(prefix); }), - endswith: new LuaBuiltinFunction((_sf, s: string, suffix: string) => { + endsWith: new LuaBuiltinFunction((_sf, s: string, suffix: string) => { return s.endsWith(suffix); }), trim: new LuaBuiltinFunction((_sf, s: string) => { diff --git a/common/space_lua/stdlib/string_test.lua b/common/space_lua/stdlib/string_test.lua index a5ae2a60..bd363649 100644 --- a/common/space_lua/stdlib/string_test.lua +++ b/common/space_lua/stdlib/string_test.lua @@ -107,11 +107,11 @@ assertEqual(parts[2], "b") assertEqual(parts[3], "c") -- Test non-standard string extensions -assertEqual(string.startswith("hello world", "hello"), true) -assertEqual(string.startswith("hello world", "world"), false) +assertEqual(string.startsWith("hello world", "hello"), true) +assertEqual(string.startsWith("hello world", "world"), false) -assertEqual(string.endswith("hello world", "world"), true) -assertEqual(string.endswith("hello world", "hello"), false) +assertEqual(string.endsWith("hello world", "world"), true) +assertEqual(string.endsWith("hello world", "hello"), false) -- Extended string.match tests -- Basic pattern matching diff --git a/lib/plugos/syscalls/datastore.ts b/lib/plugos/syscalls/datastore.ts index 3bc15b79..aeafd593 100644 --- a/lib/plugos/syscalls/datastore.ts +++ b/lib/plugos/syscalls/datastore.ts @@ -12,6 +12,7 @@ import { LuaStackFrame, luaValueToJS, } from "$common/space_lua/runtime.ts"; +import { luaBuildStandardEnv } from "$common/space_lua/stdlib.ts"; /** * Exposes the datastore API to plugs, but scoping everything to a prefix based on the plug's name @@ -49,6 +50,9 @@ export function dataStoreReadSyscalls( scopeVariables: Record = {}, ): Promise => { const dsQueryCollection = new DataStoreQueryCollection(ds, prefix); + const tl = new LuaEnv(); + tl.setLocal("_GLOBAL", commonSystem.spaceLuaEnv.env); + const sf = new LuaStackFrame(tl, null); const env = new LuaEnv(commonSystem.spaceLuaEnv.env); for (const [key, value] of Object.entries(scopeVariables)) { env.set(key, jsToLuaValue(value)); @@ -56,7 +60,7 @@ export function dataStoreReadSyscalls( return (await dsQueryCollection.query( query, env, - LuaStackFrame.lostFrame, + sf, )).map((item) => luaValueToJS(item)); }, diff --git a/plugs/core/Library/Std/Lua.md b/plugs/core/Library/Std/Lua.md index edc45b0e..e1f197a3 100644 --- a/plugs/core/Library/Std/Lua.md +++ b/plugs/core/Library/Std/Lua.md @@ -39,7 +39,7 @@ event.listen { local parents = e.data.parentNodes local foundSpaceLua = false for _, parent in ipairs(parents) do - if string.startswith(parent, "FencedCode:space-lua") or parent == "LuaDirective" then + if string.startsWith(parent, "FencedCode:space-lua") or parent == "LuaDirective" then foundSpaceLua = true end end @@ -80,7 +80,7 @@ event.listen { return end for key, val in pairs(currentValue) do - if string.startswith(key, lastProp) and val then + if string.startsWith(key, lastProp) and val then if val.call then -- We got a function if val.body then diff --git a/website/API.md b/website/API.md index 08f03ff8..c328c03c 100644 --- a/website/API.md +++ b/website/API.md @@ -1,4 +1,4 @@ This describes the APIs available in [[Space Lua]] ${template.each(query[[ - from index.tag "page" where string.startswith(name, "API/") + from index.tag "page" where string.startsWith(name, "API/") ]], templates.pageItem)} \ No newline at end of file diff --git a/website/API/string.md b/website/API/string.md index cf81dfbf..7b7baefe 100644 --- a/website/API/string.md +++ b/website/API/string.md @@ -1,5 +1,7 @@ API docs for Lua's `string` module. +**Note:** since string values set `string` as their meta table, these APIs can also be called as method calls on strings directly. For instance: `someString:startsWith("h")` is equivalent to `string.startsWith(someString, "h")`. + ## string.byte(s, i?, j?) Returns the numeric codes of characters in string `s` from position `i` to `j`. If `j` is not provided, defaults to `i`. @@ -147,20 +149,20 @@ end ``` # Non-standard Extensions -## string.startswith(s, prefix) +## string.startsWith(s, prefix) Returns true if string `s` starts with `prefix`. Example: ```lua -print(string.startswith("hello world", "hello")) -- prints: true -print(string.startswith("hello world", "world")) -- prints: false +print(string.startsWith("hello world", "hello")) -- prints: true +print(string.startsWith("hello world", "world")) -- prints: false ``` -## string.endswith(s, suffix) +## string.endsWith(s, suffix) Returns true if string `s` ends with `suffix`. Example: ```lua -print(string.endswith("hello world", "world")) -- prints: true -print(string.endswith("hello world", "hello")) -- prints: false +print(string.endsWith("hello world", "world")) -- prints: true +print(string.endsWith("hello world", "hello")) -- prints: false ``` \ No newline at end of file diff --git a/website/CHANGELOG.md b/website/CHANGELOG.md index 0fed1603..b353a16c 100644 --- a/website/CHANGELOG.md +++ b/website/CHANGELOG.md @@ -5,7 +5,22 @@ An attempt at documenting the changes/new features introduced in each release. ## Edge _These features are not yet properly released, you need to use [the edge builds](https://community.silverbullet.md/t/living-on-the-edge-builds/27) to try them._ -* **Lua Breaking change**: Converted all custom (non-standard) Lua APIs from snake_case to camelCase. This will likely result in a lot of `calling nil as function` style errors, but it's a necessary step to make the API more consistent and easier to use. Also, error reporting should now be better, and often directly navigate to the place in the code where the error occurred. +* **Lua**: _Tons_ of fixes, changes and enhancements, see [[Space Lua]] and related for up-to-date docs. Some notable things: + * [[Space Lua/Lua Integrated Query]] is now here + * Code completion of APIs in `space-lua` and Lua directive syntax + * [[API]] docs (not fully complete, but getting there). Implemented in Lua itself [[^Library/Std/Lua]]. + * WIP Lua [[^Lua]], distributed with SilverBullet core. + * [[^Library/Std/Config]] (future Lua replacement for [[^SETTINGS]]) + * [[^Library/Std/Template]] (Lua replacement of [[Templates]]) with a few samples here [[^Library/Std/Query Templates]]. + * Breaking change: API convention changed moving from `snake_case` to `camelCase` everywhere. +* `indentMultiplier` setting added (by [Mufeed Ali](https://github.com/silverbulletmd/silverbullet/pull/1212)) +* Open external links in new tab (by [Ohad Lutzky](https://github.com/silverbulletmd/silverbullet/pull/1229)) +* URL parse fixes (by [Ohad Lutzky](https://github.com/silverbulletmd/silverbullet/pull/1175)) +* [[Plugs]] are now ideally configured via [[Space Config]] (by [Marek S. Ɓukasiewicz](https://github.com/silverbulletmd/silverbullet/pull/1122)) +* Fixed styling for completed tasks with page links (by [Max Richter](https://github.com/silverbulletmd/silverbullet/pull/1225)) +* New design for [[Authentication]] page (by [majjejjam](https://github.com/silverbulletmd/silverbullet/pull/1124)) +* Tags are now easier to style (by [TR Staake](https://github.com/silverbulletmd/silverbullet/pull/1179)) +* Swift syntax highlighting now actually highlights Swift code (instead of Rust) (by [David Chiles](https://github.com/silverbulletmd/silverbullet/pull/1183)) * (Security) Implemented a lockout mechanism after a number of failed login attempts for [[Authentication]] (configured via [[Install/Configuration#Authentication]]) (by [Peter Weston](https://github.com/silverbulletmd/silverbullet/pull/1152)) ## 0.10.1 diff --git a/website/Library/Std.md b/website/Library/Std.md new file mode 100644 index 00000000..7f8f07d6 --- /dev/null +++ b/website/Library/Std.md @@ -0,0 +1,6 @@ +This is the start of the standard library distributed as part of SilverBullet core. All pages under this prefix are read-only. + +${template.each(query[[ + from index.tag "page" + where name:startsWith("Library/Std") +]], templates.pageItem)} \ No newline at end of file