summaryrefslogtreecommitdiff
path: root/src/ltm.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-21 08:46:48 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-21 09:00:32 +0100
commit23d15010edc905a3b7c123e85ef6d1960d3da039 (patch)
treed66761315763ab9e00cbed78fed69a687e02f5e3 /src/ltm.js
parent7d58c3b7314e4a63591fa375546cfc76a042e644 (diff)
downloadfengari-23d15010edc905a3b7c123e85ef6d1960d3da039.tar.gz
fengari-23d15010edc905a3b7c123e85ef6d1960d3da039.tar.bz2
fengari-23d15010edc905a3b7c123e85ef6d1960d3da039.zip
luaG_ functions
Diffstat (limited to 'src/ltm.js')
-rw-r--r--src/ltm.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/ltm.js b/src/ltm.js
index 77d65e4..f163f44 100644
--- a/src/ltm.js
+++ b/src/ltm.js
@@ -65,6 +65,21 @@ const luaT_init = function(L) {
}
};
+/*
+** Return the name of the type of an object. For tables and userdata
+** with metatable, use their '__name' metafield, if present.
+*/
+const luaT_objtypename = function(L, o) {
+ if ((o.ttistable() && o.metatable !== null)
+ || (o.ttisfulluserdata() && o.metatable !== null)) {
+ let name = o.__index(o, '__name');
+ if (name.ttisstring())
+ return name.value;
+ }
+
+ return ttypename(o.ttnov());
+};
+
const luaT_callTM = function(L, f, p1, p2, p3, hasres) {
let result = p3;
let func = L.top;
@@ -131,4 +146,5 @@ module.exports.luaT_trybinTM = luaT_trybinTM;
module.exports.luaT_callorderTM = luaT_callorderTM;
module.exports.luaT_gettmbyobj = luaT_gettmbyobj;
module.exports.luaT_init = luaT_init;
+module.exports.luaT_objtypename = luaT_objtypename;
module.exports.ttypename = ttypename; \ No newline at end of file