Skip to main content



      Home
Home » Archived » Lua Development Tools » Debugging watch window where __type has been set
Debugging watch window where __type has been set [message #898682] Fri, 27 July 2012 04:10 Go to next message
Eclipse UserFriend
I'm trying to debug some 3rd party Lua code, where they have set the __type metafield for a table. The Koneki debugger's watch window shows this value as "table: 0xc40520", rather than table[10], and I lose the ability to see what's inside the table.

Can I fix this so the watch window looks at the builtin type to decide how to display it? Where in the codebase would I look?

Thanks!

Update :

The 3rd party code is overriding the built-in type function to retrieve the __type metadata field, so the problem is just the debug watch window doesn't handle it well.
--
-- An extension to type() to identify project object types by reading the
-- "__type" field from the metatable.
--
	local builtin_type = type	
	function type(t)
		local mt = getmetatable(t)
		if (mt) then
			if (mt.__type) then
				return mt.__type
			end
		end
		return builtin_type(t)
	end


To repro, add the above plus :
local obj = {}
obj.x = 2
setmetatable( obj, { __type="blah" })
-- Set a breakpoint here, obj is table : 0xsomething in watch window
local typeofObj = type(obj)  
-- But typeofObj is correctly "blah" in watch window

[Updated on: Mon, 30 July 2012 04:18] by Moderator

Re: Debugging watch window where __type has been set [message #898784 is a reply to message #898682] Fri, 27 July 2012 10:40 Go to previous messageGo to next message
Eclipse UserFriend
Hi Richard,
I'm not sure to understand your problem.
Could you give me a simple sample of code.

On my side I test this code :

local function main()
  local t = {1,2,3}
  local m = { __type = "window" }
  setmetatable(t, m );
  
  print("ok")
end

main()


And in the Variable View, I see :
* t                     sequence[4]	
   * metatable	        table: 007C62F8
      * ["__type"]	"window"	
   * [1]	        1	
   * [2]	        2	
   * [3]	        3	
Re: Debugging watch window where __type has been set [message #898815 is a reply to message #898784] Fri, 27 July 2012 14:10 Go to previous messageGo to next message
Eclipse UserFriend
Not sure what's happening, I can repro it in my embedded lua but not in a simple test case using lua-5.1.4. Will investigate more & get back to you.
Re: Debugging watch window where __type has been set [message #898840 is a reply to message #898815] Fri, 27 July 2012 17:39 Go to previous messageGo to next message
Eclipse UserFriend
As a side case: Is there any way to modify what the inspector displays? I've looked at debugger.lua and debugintrospection.lua but can't find the code that may be used to display the text. I would like print out more information than what is shown now. Such as printing the actual table or partial table next to the type. e.g., "metatable table: 007C62F8 {__type = window, ....}". This is keeps me from having to keep expanding tables to see what they contain.
Re: Debugging watch window where __type has been set [message #899023 is a reply to message #898840] Mon, 30 July 2012 04:19 Go to previous messageGo to next message
Eclipse UserFriend
Found the issue - the 3rd party code has overridden the type function. I'd assumed it was base lua code which read the __type metafield. Updated the original with a repro.
Re: Debugging watch window where __type has been set [message #899081 is a reply to message #899023] Mon, 30 July 2012 09:54 Go to previous messageGo to next message
Eclipse UserFriend
The debugger use the global type() to know how to print variable in the UI.
The 3rd party code overrides it, and it's not really recommanded, but perhaps we could store the builtin type function in a local var at debugger initialization.

uiy uiy wrote on Fri, 27 July 2012 17:39
As a side case: Is there any way to modify what the inspector displays? I've looked at debugger.lua and debugintrospection.lua but can't find the code that may be used to display the text. I would like print out more information than what is shown now. Such as printing the actual table or partial table next to the type. e.g., "metatable table: 007C62F8 {__type = window, ....}". This is keeps me from having to keep expanding tables to see what they contain.

I'm not an expert of this part of the code and the developper which know well it has quit, as soon as I have the response I will give it to you.
Re: Debugging watch window where __type has been set [message #900695 is a reply to message #898682] Wed, 08 August 2012 04:06 Go to previous messageGo to next message
Eclipse UserFriend
I've refactored the 3rd party code so it doesn't override type(). Capturing _G.type at initialization should help, but you could also assume that any unexpected value that type() returns is actually a table.
Re: Debugging watch window where __type has been set [message #901290 is a reply to message #900695] Fri, 10 August 2012 11:55 Go to previous message
Eclipse UserFriend
It could be a good idea, I will open a bug to discuss about that.
Previous Topic:Setting up for the first time
Next Topic:Debugging Lua code launched from a Lua program
Goto Forum:
  


Current Time: Wed Jul 23 10:56:15 EDT 2025

Powered by FUDForum. Page generated in 0.83467 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top