Lua stack frame refactor
This commit is contained in:
@@ -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);
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user