diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-05-08 10:55:26 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-05-08 10:55:26 +0200 |
commit | e535c784055065ba8c8b6313b2804562c35dd261 (patch) | |
tree | 00fb42afc99e3187cfc192b750e102ebaf0df35e /src/lstring.js | |
parent | ecc153eed6f7d2fd4c39b0e276cdf14abd48d62c (diff) | |
parent | 636b1d8a5a566fac0c9c61fed44049c659435a56 (diff) | |
download | fengari-e535c784055065ba8c8b6313b2804562c35dd261.tar.gz fengari-e535c784055065ba8c8b6313b2804562c35dd261.tar.bz2 fengari-e535c784055065ba8c8b6313b2804562c35dd261.zip |
Merge remote-tracking branch 'daurnimator/boxed-strings'
Diffstat (limited to 'src/lstring.js')
-rw-r--r-- | src/lstring.js | 28 |
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; |