summaryrefslogtreecommitdiff
path: root/src/lobject.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-03-24 16:40:29 +0100
committerBenoit Giannangeli <giann008@gmail.com>2017-03-24 16:40:29 +0100
commit7af8347dbb7a8c3a09d2aebccd5f96384a7c55c3 (patch)
tree174de728b42de05b68f8ad10d1b0efddf6c188e0 /src/lobject.js
parent12944ea4d52a330b8b015af296dbbdee3fb4abbd (diff)
downloadfengari-7af8347dbb7a8c3a09d2aebccd5f96384a7c55c3.tar.gz
fengari-7af8347dbb7a8c3a09d2aebccd5f96384a7c55c3.tar.bz2
fengari-7af8347dbb7a8c3a09d2aebccd5f96384a7c55c3.zip
Proper use of luaO_nilobject
Diffstat (limited to 'src/lobject.js')
-rw-r--r--src/lobject.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 32a7573..58e2d21 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -127,6 +127,9 @@ class TValue {
}
+const luaO_nilobject = new TValue(CT.LUA_TNIL, null);
+module.exports.luaO_nilobject = luaO_nilobject;
+
const jsstring = function(value, from, to) {
let u0, u1, u2, u3, u4, u5;
let idx = 0;
@@ -169,8 +172,6 @@ const jsstring = function(value, from, to) {
return str;
};
-const nil = new TValue(CT.LUA_TNIL, null);
-
class Table extends TValue {
constructor(array, hash) {
@@ -210,14 +211,14 @@ class Table extends TValue {
__index(table, key) {
key = Table.keyValue(key);
- let v = nil;
+ let v = luaO_nilobject;
if (typeof key === 'number' && key > 0) {
v = table.value.get(key - 1); // Lua array starts at 1
} else {
v = table.value.get(key);
}
- return v ? v : nil;
+ return v ? v : luaO_nilobject;
}
__len(table) {