Page 3 of 6

Re: Unnamed GUI library

Posted: Fri Jul 22, 2011 10:00 pm
by Robin
Or just be careful about the double posting in the future.

Re: Unnamed GUI library

Posted: Fri Jul 22, 2011 10:14 pm
by GijsB
Robin, we both come from roblox were it doesnt really mater if you double post, so, yeah... ._.

Re: Unnamed GUI library

Posted: Fri Jul 22, 2011 10:20 pm
by vrld
GijsB, this isn't roblox where it doesn't t really mater if you double so, yeah... ._.

Re: Unnamed GUI library

Posted: Fri Jul 22, 2011 10:34 pm
by Trappingnoobs
Can somone look at my code though, please? I'm not sure whether you've missed the post because it's a page forward.

Second-last post (I think, or third-last or fourth-last) on page 2, I attached a .love (reluctantly :P)

If you fix it, I'd be REALY gratefull, because it's hindering me and I have no idea in the slightest what's going wrong.

Re: Unnamed GUI library

Posted: Fri Jul 22, 2011 10:37 pm
by GijsB
vrld,

sorry, but were not used to it that you can edit posts, and we keep forgetting that, so, yeah... ._.

Re: Unnamed GUI library

Posted: Sat Jul 23, 2011 8:27 am
by Robin
Trappingnoobs wrote:Can somone look at my code though, please?
Your Class.lua is a pile of WTFs. You might want to use an established class library, such as SECS, MiddleClass, HUMP.class, Slither.

Re: Unnamed GUI library

Posted: Sat Jul 23, 2011 10:16 am
by Trappingnoobs
Robin wrote:
Trappingnoobs wrote:Can somone look at my code though, please?
Your Class.lua is a pile of WTFs. You might want to use an established class library, such as SECS, MiddleClass, HUMP.class, Slither.
I don't like them :-(

Mine is made just as I'd expect it to. The bit where it asks if the key is a number is basically checking whether it has a default value. Such as this:

{Test, ["Egg"] = 1}

Test wouldn't have a default value; but 'Egg' has a default value of one. - That's the only thing I can see that'd make people wonder what on earth I was doing

Re: Unnamed GUI library

Posted: Sat Jul 23, 2011 11:40 am
by Robin
But that doesn't work at all. Only Test has a number as a key (I can't tell what type the value is, because it is a variable). The other one has 1 as value and "Egg" as key.

Also, that thing with string.dump and loadstring --- you shouldn't need that.

And you should use metatables. That's the only* way you can properly do object orientation in Lua.

* Not really the only way, but close enough.

Re: Unnamed GUI library

Posted: Sat Jul 23, 2011 11:53 am
by Trappingnoobs
Robin wrote:But that doesn't work at all. Only Test has a number as a key (I can't tell what type the value is, because it is a variable). The other one has 1 as value and "Egg" as key.

Also, that thing with string.dump and loadstring --- you shouldn't need that.

And you should use metatables. That's the only* way you can properly do object orientation in Lua.

* Not really the only way, but close enough.
Yeah I'm not the best at explaining.

Say I was programming in C#, and I wanted to make a Dog class, and I was planning in the future to do other classes, I'd do this:

Code: Select all

class LifeForm{
dead = false; --Default value of dead is false
name; --We don't set a default value
}
class Animal : LifeForm{
intelligent = false; --Animals aren't  ''intelligent'' as such in general, so we default as false
}
class Dog : Animal{
someProperty;
}
So my idea was to make that system in lua as best I could- I think I did a decent job, but the problem is that it doesn't work in certain conditions. It seems to not work with tables inside the class (Under some conditions).

So when you set the key as a string, it assumes it has a default value. If you just put in a value without a key, lua automatically assigns it the next empty number- And it knows it has no default value, so it just sets it to an empty string.

I'm not sure if I explained it well that time, either, but hopefully I did.

The point of the class system is that you can inherit from as many classes as you want- All the other systems I've looked at, including middleclass, only allow you to inherit from one, and are not structured like real implementations of OOP.

Basically this means you could do this:

Code: Select all

Class "Checkbox" {Properties}
Class "TextLabel" {Properties}
Class "CheckboxWithText" ({Properties}, {Checkbox, TextLabel})
And CheckboxWithText would get the properties from both TextLabel and Checkbox.

For some reason, though, they work FINE, APART from tables inside tables.

My event system, as you've probably seen is structured:

Code: Select all

Event = {
connect = function(s,c)
table.insert(s.functions,c)
end
functions = {}
run = function(s)
for _,v in pairs(s.functions) do
v()
end
end
}
So you can add as many functions as you'd like.

However when two classes have this, they seem to 'share' the table 'Event' between them, so when you do something like this:

Code: Select all

Button:new("Button1")
Button:new("Button2")

Button1.Event:connect(function()
print("Hello from button1")
end)
Button2.Event:connect(function()
print("Hello from button2")
end)
And then the event is ran in ONLY ONE button, this happens:

Code: Select all

Button2.Event:run()
>Hello from button1
>Hello from button2

Re: Unnamed GUI library

Posted: Sat Jul 23, 2011 12:13 pm
by T-Bone
Pics or it didn't happen :neko: