silverbullet/common/space_lua/stdlib/js.ts

29 lines
739 B
TypeScript
Raw Normal View History

2024-10-10 02:35:07 +08:00
import {
2024-10-11 21:34:27 +08:00
jsToLuaValue,
LuaBuiltinFunction,
LuaTable,
luaValueToJS,
2024-10-10 02:35:07 +08:00
} from "$common/space_lua/runtime.ts";
export const jsApi = new LuaTable({
2024-10-11 21:34:27 +08:00
new: new LuaBuiltinFunction(
(constructorFn: any, ...args) => {
return new constructorFn(
...args.map(luaValueToJS),
);
},
),
2024-10-20 21:06:23 +08:00
importModule: new LuaBuiltinFunction((_sf, url) => {
2024-10-11 21:34:27 +08:00
return import(url);
}),
2024-10-13 21:14:22 +08:00
2024-10-20 21:06:23 +08:00
tolua: new LuaBuiltinFunction((_sf, val) => jsToLuaValue(val)),
tojs: new LuaBuiltinFunction((_sf, val) => luaValueToJS(val)),
log: new LuaBuiltinFunction((_sf, ...args) => {
2024-10-11 21:34:27 +08:00
console.log(...args);
}),
// assignGlobal: new LuaBuiltinFunction((name: string, value: any) => {
// (globalThis as any)[name] = value;
// }),
2024-10-10 02:35:07 +08:00
});