Distinguish between different userdata

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
lostbuthappy
Prole
Posts: 3
Joined: Thu Oct 29, 2009 11:21 pm
Location: Germany

Distinguish between different userdata

Post by lostbuthappy »

Hello Wörld!
I just downloaded löve the other day and boy do I love it! Lua seems a bit strange at first (when you come from C++, that is), but I think I got it now... well, almost: How do I distinguish between different userdata like Image or Animation?

Code: Select all

doStuff(myImage)
function doStuff(...)
  if type(arg[1]) == "Image" then -- won't work, type returns userdata
    -- do this
  end
end
From what I read, Lua itself is not capable of that and my own experiments revealed that the type() is always "userdata". So I guess developers have to provide their own typeOf/isA-function or something like that, but I could not find anything about that in the docs/wiki.

Hope you guys can help me out. Thanks in advance!
lbh
Beware, I know umlauts!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Distinguish between different userdata

Post by bartbes »

This is not yet possible in 0.5.0, yet there is a way to do this in 0.6.0 (or there should be, I don't know the exact status): you can use tostring to tell you what kind of object it is.
User avatar
lostbuthappy
Prole
Posts: 3
Joined: Thu Oct 29, 2009 11:21 pm
Location: Germany

Re: Distinguish between different userdata

Post by lostbuthappy »

Thanks for your reply. When 0.6.0 is stable, I'll check it out. Until then I hope the missing asserts won't do too much harm :~)
Beware, I know umlauts!
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests