Override built-in type method so SoundGroup instances can be identified

This commit is contained in:
Jordan Irwin 2021-08-09 03:09:55 -07:00
parent e86d05ceaf
commit 910e7f58e7
3 changed files with 19 additions and 0 deletions

View File

@ -93,6 +93,8 @@ SoundGroup = {
end
end
def.__type = "SoundGroup"
def.__init = {
-- execute "play" methode when called directly
__call = self.play,

View File

@ -20,6 +20,7 @@ end
local scripts = {
"override",
"api",
"groups",
"node_groups",

16
override.lua Normal file
View File

@ -0,0 +1,16 @@
-- override built-in type function
local otype = type
type = function(obj)
local base_type = otype(obj)
if base_type == "table" then
local meta_type = otype(obj.__type)
if meta_type == "string" then
return obj.__type
elseif meta_type == "function" then
return obj:__type()
end
end
return base_type
end