Understanding classes
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Understanding classes
Hi, I'm pretty new here but I'm very familiar with lua. I do have a question about classes, though. I know how to create and use them, but the variable "__HAS_SECS_COMPATIBLE_CLASSES__" is confusing. Do I need to use this in every file I construct a class in or just once in my game?
Re: Understanding classes
I recommend writing your own class system. Makes more sense to yourself. :d
Hello, I am not dead.
Re: Understanding classes
I guess now I'm even more confused. I tried using the basic class system I had from other lua scripts and it threw an error. Can you provide me with a very simple, cut and dry way to create a new class?
Re: Understanding classes
foszor wrote:I guess now I'm even more confused. I tried using the basic class system I had from other lua scripts and it threw an error. Can you provide me with a very simple, cut and dry way to create a new class?
Code: Select all
function makeanewclass() --returns constructor
local n=newproxy(true)
local index={}
getmetatable(n).__index=index
getmetatable(n).__newindex=function(t,k,v)index[k]=v if string.sub(k,1,2)=="__" then getmetatable(n)[k]=v end end
getmetatable(n).__call=function() return newproxy(n) end --DO NOT TRUST THIS DIRTEH HACK, IT PROBABLY DOES NOT WORK.
return n
end
Code: Select all
local myClass=makeanewclass()
myClass.myValue=4
local myObj=myClass()
myObj.myValue=3
print(myObj.value,myClass.value)--If this prints 4,4; which it probably will, this script has failed and you must refine the __call metamethod. :P
Hello, I am not dead.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Understanding classes
Don't listen to zac, for the love of cod.
Now, did you put the SECS code in a file called class.lua (or something like that) and did you require() that file?
You don't have to use them at all. It's just a way so others can make class systems compatible to SECS, and your code can check whether it's compatible. I'd never use __HAS_SECS_COMPATIBLE_CLASSES__, don't worry about it.foszor wrote:the variable "__HAS_SECS_COMPATIBLE_CLASSES__" is confusing. Do I need to use this in every file I construct a class in or just once in my game?
Now, did you put the SECS code in a file called class.lua (or something like that) and did you require() that file?
Help us help you: attach a .love.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Understanding classes
Yeah, I've never ever seen it used . Anyway, its goal is to make it possible to use another class system, without changing code, simply by checking if it's compatible.
Re: Understanding classes
Okay thank you guys, that helped me
Who is online
Users browsing this forum: Azzla, Bing [Bot] and 8 guests