summaryrefslogtreecommitdiff
path: root/src/lua.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua.js')
-rw-r--r--src/lua.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/lua.js b/src/lua.js
index 1423750..5175bfb 100644
--- a/src/lua.js
+++ b/src/lua.js
@@ -140,9 +140,16 @@ class lua_Debug {
}
-const to_luastring = function(str, maxBytesToWrite) {
+const to_luastring_cache = {};
+
+const to_luastring = function(str, cache, maxBytesToWrite) {
assert(typeof str === "string", "to_luastring expect a js string");
+ if (cache) {
+ let cached = to_luastring_cache[str];
+ if (Array.isArray(cached)) return cached;
+ }
+
maxBytesToWrite = maxBytesToWrite !== undefined ? maxBytesToWrite : Number.MAX_SAFE_INTEGER;
let outU8Array = [];
@@ -195,6 +202,8 @@ const to_luastring = function(str, maxBytesToWrite) {
}
// Null-terminate the pointer to the buffer.
// outU8Array[outIdx] = 0;
+
+ if (cache) to_luastring_cache[str] = outU8Array;
return outU8Array;
};