aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-13 14:21:20 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-13 14:21:20 +0100
commitab14ee4aa480b21a6e5c6c4d8cdb1823951ed7c3 (patch)
treeaf213096b6f944ee00ee6c1e49d72147543ff782
parent07d15af3d893e5eecc1baffaf47fe512d6218d0b (diff)
downloadfengari-ab14ee4aa480b21a6e5c6c4d8cdb1823951ed7c3.tar.gz
fengari-ab14ee4aa480b21a6e5c6c4d8cdb1823951ed7c3.tar.bz2
fengari-ab14ee4aa480b21a6e5c6c4d8cdb1823951ed7c3.zip
Moved luaH_getn to ltable.js
-rw-r--r--src/lobject.js25
-rw-r--r--src/ltable.js30
-rw-r--r--src/lvm.js1
3 files changed, 31 insertions, 25 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 385ac9c..e206bf1 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -163,31 +163,6 @@ class Table extends TValue {
return this.luaH_getn();
}
- /*
- ** Try to find a boundary in table 't'. A 'boundary' is an integer index
- ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
- */
- luaH_getn() {
- let array = this.value.array;
- let hash = this.value.hash;
-
- let j = array.length;
- if (j > 0 && array[j - 1].ttisnil()) {
- /* there is a boundary in the array part: (binary) search for it */
- let i = 0;
- while (j - i > 1) {
- let m = (i+j)/2;
- if (array[m - 1].ttisnil()) j = m;
- else i = m;
- }
- return i;
- }
- /* else must find a boundary in hash part */
- else if (hash.size === 0)
- return j;
- else return j; // TODO: unbound_search(t, j) => but why ?
- }
-
}
class LClosure extends TValue {
diff --git a/src/ltable.js b/src/ltable.js
new file mode 100644
index 0000000..6e3af15
--- /dev/null
+++ b/src/ltable.js
@@ -0,0 +1,30 @@
+/*jshint esversion: 6 */
+"use strict";
+
+const lobject = require('./lobject.js');
+const Table = lobject.Table;
+
+/*
+** Try to find a boundary in table 't'. A 'boundary' is an integer index
+** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil).
+*/
+Table.prototype.luaH_getn = function() {
+ let array = this.value.array;
+ let hash = this.value.hash;
+
+ let j = array.length;
+ if (j > 0 && array[j - 1].ttisnil()) {
+ /* there is a boundary in the array part: (binary) search for it */
+ let i = 0;
+ while (j - i > 1) {
+ let m = (i+j)/2;
+ if (array[m - 1].ttisnil()) j = m;
+ else i = m;
+ }
+ return i;
+ }
+ /* else must find a boundary in hash part */
+ else if (hash.size === 0)
+ return j;
+ else return j; // TODO: unbound_search(t, j) => but why ?
+}; \ No newline at end of file
diff --git a/src/lvm.js b/src/lvm.js
index a23f295..890c123 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -20,6 +20,7 @@ const CallInfo = lstate.CallInfo;
const llimit = require('./llimit.js');
const ldo = require('./ldo.js');
const ltm = require('./ltm.js');
+const ltable = require('./ltable.js');
const TMS = ltm.TMS;
const RA = function(L, base, i) {