Hit a speedbump as I was learning Love and Lua

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

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

Post 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.
Geti
Party member
Posts: 112
Joined: Tue Oct 20, 2009 6:38 am

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

Post 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 :/
ShadowProtocol
Prole
Posts: 15
Joined: Thu Nov 25, 2010 9:41 pm

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

Post 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
User avatar
Mud
Citizen
Posts: 98
Joined: Fri Nov 05, 2010 4:54 am

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

Post 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()?
ShadowProtocol
Prole
Posts: 15
Joined: Thu Nov 25, 2010 9:41 pm

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

Post 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!
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post 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.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

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

Post 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)
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests