Lua: tweaks and fixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
jsToLuaValue,
|
||||
LuaBuiltinFunction,
|
||||
luaCall,
|
||||
LuaMultiRes,
|
||||
@@ -213,4 +214,13 @@ export const stringApi = new LuaTable({
|
||||
trim_end: new LuaBuiltinFunction((_sf, s: string) => {
|
||||
return s.trimEnd();
|
||||
}),
|
||||
match_regex: new LuaBuiltinFunction((_sf, s: string, pattern: string) => {
|
||||
const regex = new RegExp(pattern);
|
||||
const result = s.match(regex);
|
||||
return jsToLuaValue(result);
|
||||
// if (!result) {
|
||||
// return new LuaMultiRes([]);
|
||||
// }
|
||||
// return new LuaMultiRes(result.slice(1));
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
type ILuaFunction,
|
||||
LuaBuiltinFunction,
|
||||
type LuaEnv,
|
||||
luaEquals,
|
||||
LuaRuntimeError,
|
||||
LuaTable,
|
||||
@@ -17,7 +18,10 @@ export const tableApi = new LuaTable({
|
||||
* @returns The concatenated string.
|
||||
*/
|
||||
concat: new LuaBuiltinFunction(
|
||||
(_sf, tbl: LuaTable, sep?: string, i?: number, j?: number) => {
|
||||
(_sf, tbl: LuaTable | any[], sep?: string, i?: number, j?: number) => {
|
||||
if (Array.isArray(tbl)) {
|
||||
return tbl.join(sep);
|
||||
}
|
||||
sep = sep ?? "";
|
||||
i = i ?? 1;
|
||||
j = j ?? tbl.length;
|
||||
@@ -70,7 +74,8 @@ export const tableApi = new LuaTable({
|
||||
* @param tbl - The table to get the keys from.
|
||||
* @returns The keys of the table.
|
||||
*/
|
||||
keys: new LuaBuiltinFunction((_sf, tbl: LuaTable) => {
|
||||
keys: new LuaBuiltinFunction((_sf, tbl: LuaTable | LuaEnv) => {
|
||||
console.log("Keys", tbl);
|
||||
return tbl.keys();
|
||||
}),
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user