[Lua] Adds some useful encoding APIs for Lua (base64 encoding and decoding and such).

This commit is contained in:
Zef Hemel
2025-08-20 13:39:34 +02:00
parent 90487746fd
commit c16dbc12fb
5 changed files with 48 additions and 1 deletions
+19
View File
@@ -0,0 +1,19 @@
import { LuaBuiltinFunction, LuaTable } from "../runtime.ts";
import { base64Decode, base64Encode } from "../../crypto.ts";
export const encodingApi = new LuaTable({
base64Encode: new LuaBuiltinFunction(
(_sf, s: string | Uint8Array): string => {
return base64Encode(s);
},
),
base64Decode: new LuaBuiltinFunction((_sf, s: string): Uint8Array => {
return base64Decode(s);
}),
utf8Encode: new LuaBuiltinFunction((_sf, s: string): Uint8Array => {
return new TextEncoder().encode(s);
}),
utf8Decode: new LuaBuiltinFunction((_sf, data: Uint8Array): string => {
return new TextDecoder().decode(data);
}),
});