summaryrefslogtreecommitdiff
path: root/src/lstring.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-08 18:26:14 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-08 18:26:14 +1000
commit636b1d8a5a566fac0c9c61fed44049c659435a56 (patch)
tree99ee78a56e98f09bcb7a1255b34b5638b8c776f3 /src/lstring.js
parent48d20ce3e2b38d1da536e42f225401fc06147d2a (diff)
downloadfengari-636b1d8a5a566fac0c9c61fed44049c659435a56.tar.gz
fengari-636b1d8a5a566fac0c9c61fed44049c659435a56.tar.bz2
fengari-636b1d8a5a566fac0c9c61fed44049c659435a56.zip
Introduce a TString class
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;