Changelog updates and Lua fixes
parent
107b232f49
commit
fb7be2a45a
|
@ -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) => {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<string, any> = {},
|
||||
): Promise<any[]> => {
|
||||
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));
|
||||
},
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)}
|
|
@ -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
|
||||
```
|
|
@ -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
|
||||
|
|
|
@ -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)}
|
Loading…
Reference in New Issue