Page 2 of 2

Re: Hit a speedbump as I was learning Love and Lua

Posted: Fri Nov 26, 2010 12:32 am
by Mud
So I need a giant library to use classes?
Not really. The book you're reading right now has a chapter on classes. If your needs are simple (don't need multiple inheritance, up-casting, etc.), you can get away with just this for simple prototype based inheritance:

Code: Select all

local Class = {}
function Class:new (o)
  o = o or {}
  setmetatable(o, self)
  self.__index = self
  return o
end
One of the beauties of Lua is that you don't pay for stuff you don't want/need. If you need classes, or properties, or some other feature language X has, you can probably implement that feature in Lua itself using it's metaprogramming facilities.

Re: Hit a speedbump as I was learning Love and Lua

Posted: Fri Nov 26, 2010 2:47 am
by Geti
@trookat yeah, you got it right in the end. Could be a good idea to make sure you are before posting with a disclaimer though, haha.

If you're looking for a more thorough, mature library, LOOP is pretty good. It'd be nice to see some sort of class system integrated into love itself but I can't see that happening for a while :/

Re: Hit a speedbump as I was learning Love and Lua

Posted: Fri Nov 26, 2010 4:26 am
by ShadowProtocol
Thanks for the replies, but Trookat came into my topic and kind of hijacked it, posting his own questions, blocking mine from being noticed and receiving responses. Can someone please go back to the previous page and read my last post and go through each comment I made, pointing out which are wrong?

Thanks

Re: Hit a speedbump as I was learning Love and Lua

Posted: Fri Nov 26, 2010 5:32 am
by Mud
ShadowProtocol wrote:Trookat came into my topic and kind of hijacked it, posting his own questions, blocking mine from being noticed and receiving responses
Trookat didn't hijack your topic, he answered your question. :huh:
ShadowProtocol wrote:-- Can you explain why a newly created object has the value of another instance, and not the default of the class?
anotherObject = object:new()
If you wanted anotherObject to be an instance of myclass, then why did you use object:new() rather than myclass:new()?

Re: Hit a speedbump as I was learning Love and Lua

Posted: Fri Nov 26, 2010 5:34 am
by ShadowProtocol
Mud wrote:
ShadowProtocol wrote:Trookat came into my topic and kind of hijacked it, posting his own questions, blocking mine from being noticed and receiving responses
Trookat didn't hijack your topic, he answered your question. :huh:
ShadowProtocol wrote:-- Can you explain why a newly created object has the value of another instance, and not the default of the class?
anotherObject = object:new()
If you wanted anotherObject to be an instance of myclass, then why did you use object:new() rather than myclass:new()?
I didn't do anything, I was making comments with my own interpretation of the code, and I was asking you guys to, like a teacher, tell me where I was wrong and where I was right. I didn't write that code, it was posted as an example of a library, and I was just simply trying to figure out if I was understanding the example properly. :|

Forget it, I don't need so much hand-holding. I'm gonna check out MiddleClass and take the time to create test cases and learn while reading/doing. Thanks!

Re: Hit a speedbump as I was learning Love and Lua

Posted: Fri Nov 26, 2010 7:03 am
by bartbes
Time to clarify, using SECS every object is a class of its own, so when you created a class from the object, you used that as superclass, and as such it inherited its values.

Re: Hit a speedbump as I was learning Love and Lua

Posted: Fri Nov 26, 2010 4:59 pm
by kikito
ShadowProtocol wrote:
Forget it, I don't need so much hand-holding. I'm gonna check out MiddleClass and take the time to create test cases and learn while reading/doing. Thanks!
FYI, test cases are already written (have a look at Object_spec.lua on that repo)