lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>From dmarks@dionysus.phs.uiuc.edu Sun May 10 02:47:13 1998
>
>I was perusing the lua 3.0 documentation, and I was looking for a tag
>method that could be overridden for tostring() and tonumber().  Do
>these exist?  If not, they might be a useful addition to the language
>so that userdatas could be more easily debugged.

Why not redefine tostring() and tonumber() to handle userdata in a special way?
Something like:

oldtostring=tostring

function tostring(x)
	if type(x)=="userdata" then
		...
	else
		return oldtostring(x)
	end
end

In Lua 3.1, you can use an upvalue instead of oldtostring:

function tostring(x)
	if type(x)=="userdata" then
		...
	else
		return %tostring(x)
	end
end

--lhf