Lua stack frame refactor
This commit is contained in:
@@ -13,13 +13,13 @@ export const jsApi = new LuaTable({
|
||||
);
|
||||
},
|
||||
),
|
||||
importModule: new LuaBuiltinFunction((url) => {
|
||||
importModule: new LuaBuiltinFunction((_sf, url) => {
|
||||
return import(url);
|
||||
}),
|
||||
|
||||
tolua: new LuaBuiltinFunction(jsToLuaValue),
|
||||
tojs: new LuaBuiltinFunction(luaValueToJS),
|
||||
log: new LuaBuiltinFunction((...args) => {
|
||||
tolua: new LuaBuiltinFunction((_sf, val) => jsToLuaValue(val)),
|
||||
tojs: new LuaBuiltinFunction((_sf, val) => luaValueToJS(val)),
|
||||
log: new LuaBuiltinFunction((_sf, ...args) => {
|
||||
console.log(...args);
|
||||
}),
|
||||
// assignGlobal: new LuaBuiltinFunction((name: string, value: any) => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { LuaBuiltinFunction, LuaTable } from "$common/space_lua/runtime.ts";
|
||||
|
||||
export const osApi = new LuaTable({
|
||||
time: new LuaBuiltinFunction((tbl?: LuaTable) => {
|
||||
time: new LuaBuiltinFunction((_sf, tbl?: LuaTable) => {
|
||||
if (tbl) {
|
||||
// Build a date object from the table
|
||||
const date = new Date();
|
||||
@@ -32,7 +32,7 @@ export const osApi = new LuaTable({
|
||||
* If format is not "*t", then date returns the date as a string, formatted according to the same rules as the ISO C function strftime.
|
||||
* If format is absent, it defaults to "%c", which gives a human-readable date and time representation using the current locale.
|
||||
*/
|
||||
date: new LuaBuiltinFunction((format: string, timestamp?: number) => {
|
||||
date: new LuaBuiltinFunction((_sf, format: string, timestamp?: number) => {
|
||||
const date = timestamp ? new Date(timestamp * 1000) : new Date();
|
||||
|
||||
// Default Lua-like format when no format string is provided
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from "$common/space_lua/runtime.ts";
|
||||
|
||||
export const stringApi = new LuaTable({
|
||||
byte: new LuaBuiltinFunction((s: string, i?: number, j?: number) => {
|
||||
byte: new LuaBuiltinFunction((_sf, s: string, i?: number, j?: number) => {
|
||||
i = i ?? 1;
|
||||
j = j ?? i;
|
||||
const result = [];
|
||||
@@ -15,11 +15,11 @@ export const stringApi = new LuaTable({
|
||||
}
|
||||
return new LuaMultiRes(result);
|
||||
}),
|
||||
char: new LuaBuiltinFunction((...args: number[]) => {
|
||||
char: new LuaBuiltinFunction((_sf, ...args: number[]) => {
|
||||
return String.fromCharCode(...args);
|
||||
}),
|
||||
find: new LuaBuiltinFunction(
|
||||
(s: string, pattern: string, init?: number, plain?: boolean) => {
|
||||
(_sf, s: string, pattern: string, init?: number, plain?: boolean) => {
|
||||
init = init ?? 1;
|
||||
plain = plain ?? false;
|
||||
const result = s.slice(init - 1).match(pattern);
|
||||
@@ -32,7 +32,7 @@ export const stringApi = new LuaTable({
|
||||
]);
|
||||
},
|
||||
),
|
||||
format: new LuaBuiltinFunction((format: string, ...args: any[]) => {
|
||||
format: new LuaBuiltinFunction((_sf, format: string, ...args: any[]) => {
|
||||
return format.replace(/%./g, (match) => {
|
||||
switch (match) {
|
||||
case "%s":
|
||||
@@ -44,7 +44,7 @@ export const stringApi = new LuaTable({
|
||||
}
|
||||
});
|
||||
}),
|
||||
gmatch: new LuaBuiltinFunction((s: string, pattern: string) => {
|
||||
gmatch: new LuaBuiltinFunction((_sf, s: string, pattern: string) => {
|
||||
const regex = new RegExp(pattern, "g");
|
||||
return () => {
|
||||
const result = regex.exec(s);
|
||||
@@ -55,7 +55,7 @@ export const stringApi = new LuaTable({
|
||||
};
|
||||
}),
|
||||
gsub: new LuaBuiltinFunction(
|
||||
(s: string, pattern: string, repl: string, n?: number) => {
|
||||
(_sf, s: string, pattern: string, repl: string, n?: number) => {
|
||||
n = n ?? Infinity;
|
||||
const regex = new RegExp(pattern, "g");
|
||||
let result = s;
|
||||
@@ -70,17 +70,17 @@ export const stringApi = new LuaTable({
|
||||
return result;
|
||||
},
|
||||
),
|
||||
len: new LuaBuiltinFunction((s: string) => {
|
||||
len: new LuaBuiltinFunction((_sf, s: string) => {
|
||||
return s.length;
|
||||
}),
|
||||
lower: new LuaBuiltinFunction((s: string) => {
|
||||
lower: new LuaBuiltinFunction((_sf, s: string) => {
|
||||
return luaToString(s.toLowerCase());
|
||||
}),
|
||||
upper: new LuaBuiltinFunction((s: string) => {
|
||||
upper: new LuaBuiltinFunction((_sf, s: string) => {
|
||||
return luaToString(s.toUpperCase());
|
||||
}),
|
||||
match: new LuaBuiltinFunction(
|
||||
(s: string, pattern: string, init?: number) => {
|
||||
(_sf, s: string, pattern: string, init?: number) => {
|
||||
init = init ?? 1;
|
||||
const result = s.slice(init - 1).match(pattern);
|
||||
if (!result) {
|
||||
@@ -89,18 +89,18 @@ export const stringApi = new LuaTable({
|
||||
return new LuaMultiRes(result.slice(1));
|
||||
},
|
||||
),
|
||||
rep: new LuaBuiltinFunction((s: string, n: number, sep?: string) => {
|
||||
rep: new LuaBuiltinFunction((_sf, s: string, n: number, sep?: string) => {
|
||||
sep = sep ?? "";
|
||||
return s.repeat(n) + sep;
|
||||
}),
|
||||
reverse: new LuaBuiltinFunction((s: string) => {
|
||||
reverse: new LuaBuiltinFunction((_sf, s: string) => {
|
||||
return s.split("").reverse().join("");
|
||||
}),
|
||||
sub: new LuaBuiltinFunction((s: string, i: number, j?: number) => {
|
||||
sub: new LuaBuiltinFunction((_sf, s: string, i: number, j?: number) => {
|
||||
j = j ?? s.length;
|
||||
return s.slice(i - 1, j);
|
||||
}),
|
||||
split: new LuaBuiltinFunction((s: string, sep: string) => {
|
||||
split: new LuaBuiltinFunction((_sf, s: string, sep: string) => {
|
||||
return s.split(sep);
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
|
||||
export const tableApi = new LuaTable({
|
||||
concat: new LuaBuiltinFunction(
|
||||
(tbl: LuaTable, sep?: string, i?: number, j?: number) => {
|
||||
(_sf, tbl: LuaTable, sep?: string, i?: number, j?: number) => {
|
||||
sep = sep ?? "";
|
||||
i = i ?? 1;
|
||||
j = j ?? tbl.length;
|
||||
@@ -18,7 +18,7 @@ export const tableApi = new LuaTable({
|
||||
},
|
||||
),
|
||||
insert: new LuaBuiltinFunction(
|
||||
(tbl: LuaTable, posOrValue: number | any, value?: any) => {
|
||||
(_sf, tbl: LuaTable, posOrValue: number | any, value?: any) => {
|
||||
if (value === undefined) {
|
||||
value = posOrValue;
|
||||
posOrValue = tbl.length + 1;
|
||||
@@ -26,11 +26,11 @@ export const tableApi = new LuaTable({
|
||||
tbl.insert(posOrValue, value);
|
||||
},
|
||||
),
|
||||
remove: new LuaBuiltinFunction((tbl: LuaTable, pos?: number) => {
|
||||
remove: new LuaBuiltinFunction((_sf, tbl: LuaTable, pos?: number) => {
|
||||
pos = pos ?? tbl.length;
|
||||
tbl.remove(pos);
|
||||
}),
|
||||
sort: new LuaBuiltinFunction((tbl: LuaTable, comp?: ILuaFunction) => {
|
||||
return tbl.sort(comp);
|
||||
sort: new LuaBuiltinFunction((sf, tbl: LuaTable, comp?: ILuaFunction) => {
|
||||
return tbl.sort(comp, sf);
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user