generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Class system for RbxUtility - Proposed syntax

Previous Thread :: Next Thread 
Intune is not online. Intune
Joined: 02 Feb 2012
Total Posts: 50
10 Feb 2012 06:17 PM
Where do you all learn to do this kind of stuff?

Or at least where you learn what all these terms mean, what they are used for, and in what context they would be used?
Report Abuse
KingBoo is not online. KingBoo
Joined: 16 Jul 2007
Total Posts: 8495
11 Feb 2012 09:58 PM
Oh oh oh! Add constructors and destructors.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
11 Feb 2012 10:13 PM
"Add constructors and destructors."

Did I not mention constructors?

The "Create" method is a constructor if you define it. As for destructors, you should not use destructors in a garbage collected language other than explicit ones, since you'll get really ugly code otherwise, as you can control the destruction order very well.
Report Abuse
TorrentsAndXDCC is not online. TorrentsAndXDCC
Joined: 18 Dec 2010
Total Posts: 163
11 Feb 2012 11:10 PM
Stravant, what are your thoughts on OO in Lua?

I recently implemented my own class library for a Love2d school project (awesome to work on).
But it felt bloaty and wrong. I've never used OOP in any serious project before.
While it did make organizing objects easier, and I did manage to extend things more easily, but I still don't like.
I think I could have managed this with enough time, without the undue overhead.

I've also recently read some descriptions of Lua, and something that came up often is its lack of general OOP.
One problem is that without it, everyone writes their own implementations, which build up if you start using lots of other peoples code.
Another thing that was apparent is that Lua is not meant to have classes in the normal sense.
It's meant to be more do-it yourself, or at least not very focused on classes.

Now I think I'll convert to a more simplistic class approach.

Anyway, do you prefer to use classes in Lua?
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
11 Feb 2012 11:29 PM
I can't write without them, at least for anything in the 500+ line range, which most of my stuff is. I need to use classes to keep the "who's responsible for what" of a project straight in my head.

You can see my usual system that I use for my personal code in some of the gear that I made. It's about as stripped down as you can get while maintaining and object oriented feel. Just one simple ~20 line function need to be included to power it, and it also looks quite elegant since it's kept in a logical block for the definition.
Report Abuse
NXTBoy is not online. NXTBoy
Joined: 25 Aug 2008
Total Posts: 4533
12 Feb 2012 03:31 AM
How does it cope with metamethods? While I can see that `__index` and `__newindex` are probably not a good idea to be allowed to be overriden, it would be nice to override the mathematical operators. Could you maybe add `def.__meta.sub`, or even just `def.__sub`?
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
16 Aug 2012 06:28 PM
Bump.

I want to know if you've updated this at all, Stravant.
I also want you opinions on implementing inheritance. (something I am only vaguely familiar with)

I was thinking of something like this:

Add the implementer as an "Inherit" method to each class definition (classDef). This way when you want to inherit from that class you call the implementor on the new class implementation proxy (mainImplProxy). Inheriting from another class would have to disable all of the re-definition errors...

As I am inexperienced with OOP I'm not sure how well this would go. I should experiment more, but I wanted to make this post before starting.
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
16 Aug 2012 07:00 PM
@NecroBumpist

His Signal class is in the RbxUtility library, but we already have BindableEvents.

His Create function has been put in the RbxUtility library too, and I've started using it, but it currently contains an error. I told him and he said he was going to try to get it fixed.

Finally, his class system isn't in the RbxUtility library yet.
Report Abuse
AdvRobot is not online. AdvRobot
Joined: 09 Aug 2012
Total Posts: 172
16 Aug 2012 08:10 PM
This is very professionally coded. It is organized, simply wonderful! This is glorious.
Report Abuse
ENET is not online. ENET
Joined: 01 Jan 2010
Total Posts: 4820
16 Aug 2012 08:45 PM
Could do something like this...

local private = {};
setmetatable(private, {
__index = function(t, k)
local val = rawget(t, k);
print(val == nil);
if(not val)then
return (function(table, func, ...)
rawset(t, k, function(...)
print('Halleluja');
func(...);
end);
print("Declared private method: ", k);
end)
else
error("Can't re-declare a private method!", k);
end
end
});

private:bob(function() end);
private:bob(function() end);

> true
> Declared private method: bob
> Halleluja
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
16 Aug 2012 09:20 PM
@Necro:
The only way to do inheritance with parameter forwarding and have it actually semantically valid in all cases is either to do this:

class Blah somehow Extends foo(function(def)
function def:Create(base, ...)
self = base(args)
...
end
end)

Which is not the nicest, but _will_ work. The main downside is that it requires creating a closure every time something is instantiated, and a lot of the time the base class may not even need constructor arguments, which makes make it need that extra line.

Option 2: Allow for a "bind" function that knows how to generate the base' arguments from the arguments given. This may lead to repeated work so it's not really ideal either.

It's kind of a hard problem.
Report Abuse
popinman322 is not online. popinman322
Joined: 04 Mar 2009
Total Posts: 5184
16 Aug 2012 09:25 PM
The arguments for the base class could be pulled from the stack of arguments?
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
16 Aug 2012 09:45 PM
@Stravant:

I really don't understand what you're trying to get at :|

Anyway, I implemented the solution I mentioned last post, which seems to work for incredibly simple inheritance.
As I find the need I will try to figure out how to better solve this problem in general.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
16 Aug 2012 09:46 PM
What I'm talking about is constructor argument forwarding.

The arguments to the base class may not be in the same order as to the derived class, or not even be in the derived class argument list at all. Even see one of the most common cases:

class Widget {
Widget(WidgetType type)
};

class List {
List(elements): Widget(WIDGETTYPE_LIST) {
...
}
};

If it's not possible to do that it's not even worth having base classes with constructor arguments at all.
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
16 Aug 2012 10:40 PM
Tis easy.

provide each Class Definition with a list of all the methods.
Use that list to call whatever superclass functions you need.

class "subclass" (function(def)
function def:Create()
Superclass.Methods.Create(self);
-- stuff
end
end)
Report Abuse
Previous Thread :: Next Thread 
Page 2 of 2Go to page: 1, [2] Prev
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image