Skip to content

Commit

Permalink
Lua math lib fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel committed Jan 17, 2025
1 parent 0076208 commit 6a65912
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion common/space_lua/stdlib/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ export const mathApi = new LuaTable({

// Keep the cosine_similarity utility function
cosine_similarity: new LuaBuiltinFunction(
(sf, vecA: number[], vecB: number[]) => {
(sf, vecA: LuaTable | number[], vecB: LuaTable | number[]) => {
// Convert LuaTable to number[]
if (vecA instanceof LuaTable) {
vecA = vecA.toJSArray();
}
if (vecB instanceof LuaTable) {
vecB = vecB.toJSArray();
}

if (vecA.length !== vecB.length) {
throw new LuaRuntimeError("Vectors must be of the same length", sf);
}
Expand Down
9 changes: 9 additions & 0 deletions common/space_lua/stdlib/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,13 @@ export const stringApi = new LuaTable({
endswith: new LuaBuiltinFunction((_sf, s: string, suffix: string) => {
return s.endsWith(suffix);
}),
trim: new LuaBuiltinFunction((_sf, s: string) => {
return s.trim();
}),
trim_start: new LuaBuiltinFunction((_sf, s: string) => {
return s.trimStart();
}),
trim_end: new LuaBuiltinFunction((_sf, s: string) => {
return s.trimEnd();
}),
});

0 comments on commit 6a65912

Please sign in to comment.