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:
@@ -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);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user