lotrointerface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

Reply
Thread Tools Display Modes
  #1  
Unread 03-06-2021, 10:38 PM
Ivandar Ivandar is offline
The Wary
 
Join Date: Mar 2021
Posts: 2
class's IsA() function for user-defined classes

Hello web-mind!

So, it seems that the class definition provided in Class.lua by Turbine (that a lot of folks use in their scripts) has a bug (feature?) with the IsA() command it defines.

Specifically, while it seems to work for Turbine-defined classes, it's not working for user-defined classes. At least, that's what I'm finding, and at least one other (and experienced) user has as well.

Has anyone encountered and solved this same issue?

Thanks!
Reply With Quote
  #2  
Unread 03-07-2021, 08:26 AM
Garan's Avatar
Garan Garan is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Oct 2010
Posts: 340
It seems there are two versions of Class.lua that were published. The first, probaby published while Lua was still in Beta, possibly by another plugin author, uses metatables to determine class types. The second, published by Turbine, uses an internal table to keep track of class types. I include the first version in my plugins and have never used the IsA() function so I never noticed it doesn't seem to work for user classes (the Class() function works fine otherwise). It seems that the IsA() from the second version might work correctly for Turbine defined classes as well as user classes.

The second version is included in any of the libraries that are found by entering "Turbine" in the "Search Downloads" field. That may help.
EDIT: Note, the version of Class.lua in these libraries has a dependancy on the Type.lua also found in these libraries.

Hmmm, after some testing with the second version (the one from the libraries available here), I got mixed results. My simple test code was:
Code:
abc=class(Turbine.UI.Window)
function abc:Constructor()
	Turbine.UI.Window.Constructor(self)
end
w1=Turbine.UI.Window()
w2=abc()
def=class(abc)
function def:Constructor()
	abc.Constructor(self)
end
w3=def()

Turbine.Shell.WriteLine("w1,window:"..tostring(w1:IsA(Turbine.UI.Window)))
Turbine.Shell.WriteLine("w1,control:"..tostring(w1:IsA(Turbine.UI.Control)))
Turbine.Shell.WriteLine("w2,window:"..tostring(w2:IsA(Turbine.UI.Window)))
Turbine.Shell.WriteLine("w2,control:"..tostring(w2:IsA(Turbine.UI.Control)))
Turbine.Shell.WriteLine("w2,abc:"..tostring(w2:IsA(abc)))
Turbine.Shell.WriteLine("w3,window:"..tostring(w3:IsA(Turbine.UI.Window)))
Turbine.Shell.WriteLine("w3,control:"..tostring(w3:IsA(Turbine.UI.Control)))
Turbine.Shell.WriteLine("w3,abc:"..tostring(w3:IsA(abc)))
Turbine.Shell.WriteLine("w3,def:"..tostring(w3:IsA(def)))

Turbine.Shell.WriteLine("abc,window:"..tostring(abc:IsA(Turbine.UI.Window)))
Turbine.Shell.WriteLine("def,window:"..tostring(def:IsA(Turbine.UI.Window)))
Turbine.Shell.WriteLine("def,abc:"..tostring(def:IsA(abc)))
The results were:
Code:
w1,window:true
w1,control:true
w2,window:false
w2,control:false
w2,abc:true
w3,window:false
w3,control:false
w3,abc:true
w3,def:true
abc,window:true
def,window:false
def,abc:true
so,
instances of system defined classes will show true for the class they instantiate and parent classes
instances of user defined classes will not show as instances of the system defined parent of the class they instantiate but will show any user defined class in the hierarchy
it works similarly for the classes themselves with a disconnect at the first user defined class in the hierarchy,
user classes directly derived from a system class will show as derived from that class (and it's parents) but any user class derived from a user class will only show true for the user defined parents in it's hierarchy.

Odd. But, as mentioned earlier, I don't use IsA() anyway so this is about as far as I will investigate, but it does look like there might be a bug in the Turbine implementation

Anyone else actually use the IsA() function that can shed more light?

EDIT2: it seems my version actually came from a plugin author, source currently unknown. I suspect it came from an author, not Turbine, due to the use of the variable "klass" which would imply a non-english source, swedish perhaps?

Last edited by Garan : 03-07-2021 at 12:56 PM.
Reply With Quote
  #3  
Unread 03-07-2021, 03:38 PM
Thurallor's Avatar
Thurallor Thurallor is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: May 2013
Posts: 202
I never use IsA(), mostly because I tried it a long time ago and it didn't seem to work. I use the Class.lua and Type.lua from the Turbine library.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
class plugins Barb7 Interface Requests (L) 1 03-06-2020 03:30 AM
Binding events to classes Carentil Lua Programming Help (L) 4 11-18-2013 08:19 AM
Function to Get Scrolling Combat Text jabjab Lua Programming Help (L) 1 02-20-2012 11:27 PM
Nested Classes issue SanDBoX Lua Programming Help (L) 7 10-27-2011 10:30 AM
[Class] PercentBar itsallhype820 Tutorials & Other Helpful Information (L) 0 10-13-2011 12:47 AM


All times are GMT -5. The time now is 02:17 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui