Breaking Lua API changes:

* tpl -> template.new
* define_command -> command.define
* define_event_listener -> event.listen
* tag -> index.tag

Updated in the docs
This commit is contained in:
Zef Hemel
2025-01-19 14:32:11 +01:00
parent 72b4ecdc36
commit 6078452a6c
22 changed files with 275 additions and 237 deletions
+18
View File
@@ -1,8 +1,10 @@
import {
type ILuaFunction,
jsToLuaValue,
LuaBuiltinFunction,
LuaTable,
} from "$common/space_lua/runtime.ts";
import { interpolateLuaString } from "$common/space_lua/stdlib/space_lua.ts";
export const templateApi = new LuaTable({
each: new LuaBuiltinFunction(
@@ -17,4 +19,20 @@ export const templateApi = new LuaTable({
return result.join("");
},
),
new: new LuaBuiltinFunction(
(_sf, template: string): ILuaFunction => {
const lines = template.split("\n").map((line) =>
line.replace(/^\s{4}/, "")
);
const processed = lines.join("\n");
return new LuaBuiltinFunction(
async (sf, env: LuaTable | any) => {
if (!(env instanceof LuaTable)) {
env = jsToLuaValue(env);
}
return await interpolateLuaString(sf, processed, env);
},
);
},
),
});