From e96d75a87d879f7f455e4b9c6457bf6580743fa5 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Mon, 6 Mar 2017 15:58:11 +0100 Subject: String are represented by Array of 8-bit numbers --- src/lstate.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/lstate.js') diff --git a/src/lstate.js b/src/lstate.js index 2e6ebbe..519abde 100644 --- a/src/lstate.js +++ b/src/lstate.js @@ -69,7 +69,7 @@ class global_State { constructor(L) { this.mainthread = L; - this.strt = null; // TODO: string hash table + this.strt = new Map(); this.l_registry = nil; this.panic = null; this.version = null; @@ -77,6 +77,15 @@ class global_State { this.mt = new Array(LUA_NUMTAGS); } + intern(stringArray) { + let key = stringArray.map(e => `${e}|`).join(''); + + if (!this.strt.has(key)) + this.strt.set(key, new lobject.TValue(CT.LUA_TLNGSTR, stringArray)); + + return this.strt.get(key); + } + } -- cgit v1.2.3-54-g00ecf