summaryrefslogtreecommitdiff
path: root/src/lstring.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lstring.js')
-rw-r--r--src/lstring.js28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/lstring.js b/src/lstring.js
index af434c6..3e94171 100644
--- a/src/lstring.js
+++ b/src/lstring.js
@@ -1,20 +1,41 @@
"use strict";
+const assert = require("assert");
+
const defs = require('./defs.js');
+class TString {
+
+ constructor(L, str) {
+ this.realstring = str;
+ }
+
+ getstr() {
+ return this.realstring;
+ }
+
+ tsslen() {
+ return this.realstring.length;
+ }
+
+}
+
const luaS_eqlngstr = function(a, b) {
- return a == b || (a.length == b.length && a.join() == b.join());
+ assert(a instanceof TString);
+ assert(b instanceof TString);
+ return a == b || (a.realstring.length == b.realstring.length && a.realstring.join() == b.realstring.join());
};
/* converts strings (arrays) to a consistent map key */
const luaS_hash = function(str) {
- return str.map(e => `${e}|`).join('');
+ assert(str instanceof TString);
+ return str.realstring.map(e => `${e}|`).join('');
};
/* variant that takes ownership of array */
const luaS_bless = function(L, str) {
Object.freeze(str);
- return str;
+ return new TString(L, str);
};
/* makes a copy */
@@ -32,3 +53,4 @@ module.exports.luaS_hash = luaS_hash;
module.exports.luaS_bless = luaS_bless;
module.exports.luaS_new = luaS_new;
module.exports.luaS_newliteral = luaS_newliteral;
+module.exports.TString = TString;