diff --git a/worldeditadditions/utils/inspect.lua b/worldeditadditions/utils/inspect.lua index f8072c9..d5ed030 100644 --- a/worldeditadditions/utils/inspect.lua +++ b/worldeditadditions/utils/inspect.lua @@ -1,5 +1,10 @@ --- Serialises an arbitrary value to a string. -- Note that although the resulting table *looks* like valid Lua, it isn't. +-- Completely arbitrarily, if a table (or it's associated metatable) has the +-- key __name then it is conidered the name of the parent metatable. This can +-- be useful for identifying custom table-based types. +-- Should anyone come across a 'proper' way to obtain the name of a metatable +-- in pure vanilla Lua, I will update this to follow that standard instead. -- @param item any Input item to serialise. -- @param sep string key value seperator -- @param new_line string key value pair delimiter @@ -12,7 +17,13 @@ local function inspect(item, maxdepth) end if maxdepth < 1 then return "[truncated]" end - local result = { "{\n" } + local result = { } + -- Consider our (arbitrarily decided) property __name to the type of this item + -- Remember that this implicitly checks the metatable so long as __index is set. + if type(item.__name) == "string" then + table.insert(result, "("..item.__name..") ") + end + table.insert(result, "{\n") for key,value in pairs(item) do local value_text = inspect(value, maxdepth - 1) :gsub("\n", "\n\t") diff --git a/worldeditadditions/utils/vector3.lua b/worldeditadditions/utils/vector3.lua index 8558453..efff729 100644 --- a/worldeditadditions/utils/vector3.lua +++ b/worldeditadditions/utils/vector3.lua @@ -2,6 +2,7 @@ -- @class local Vector3 = {} Vector3.__index = Vector3 +Vector3.__name = "Vector3" -- A hack to allow identification in wea.inspect --- Creates a new Vector3 instance. -- @param x number The x co-ordinate value.