Difference between revisions of "Debug.settypemt"
From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>") |
|||
(6 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
− | '''Available since:''' Gideros 2016.08<br/> | + | <languages /> |
− | === Description === | + | '''<translate>Available since</translate>:''' Gideros 2016.08<br/> |
− | Set meta table type | + | '''<translate>Class</translate>:''' [[Special:MyLanguage/debug|debug]]<br/> |
+ | === <translate>Description</translate> === | ||
+ | <translate>Set meta table type | ||
From http://lua-users.org/wiki/LuaPowerPatches | From http://lua-users.org/wiki/LuaPowerPatches | ||
Line 19: | Line 21: | ||
print(s[8]) --> w | print(s[8]) --> w | ||
</code></pre> | </code></pre> | ||
− | Also sets table library as default type metatable for all tables without user defined metatables i.e. enables following syntax: t:insert(3); t:remove(2); t:sort(func); etc. | + | Also sets table library as default type metatable for all tables without user defined metatables i.e. enables following syntax: t:insert(3); t:remove(2); t:sort(func); etc.</translate> |
− | < | + | <syntaxhighlight lang="lua"> |
debug.settypemt() | debug.settypemt() | ||
− | </ | + | </syntaxhighlight> |
+ | |||
+ | {{Debug}} |
Latest revision as of 14:26, 13 July 2023
Available since: Gideros 2016.08
Class: debug
Description
Set meta table type
From http://lua-users.org/wiki/LuaPowerPatches Useful to extend Lua syntax and for some tricks.
Adds new method to debug library: debug.settypemt(type, metatable) Supported types: "nil","boolean","lightuserdata","number","string","table","function","userdata","thread".
For example:
<code> -- enable string indexing (s[n]) to get character at utf8 position string.__index = function(s, n) return utf8.sub(s, n, n) end debug.settypemt("string", string) local s = "Hello, world!" print(s[8]) --> w </code>
Also sets table library as default type metatable for all tables without user defined metatables i.e. enables following syntax: t:insert(3); t:remove(2); t:sort(func); etc.
debug.settypemt()