View previous topic :: View next topic |
Author |
Message |
dhasenan
Joined: 03 Feb 2005 Posts: 73 Location: New York
|
Posted: Thu May 29, 2008 7:54 am Post subject: Faking multiple inheritance |
|
|
Hi,
I want to fake multiple inheritance in MiniD. Given that objects are open to addition after definition, this should be relatively easy, as long as I can iterate through the fields and methods of a given object:
Code: |
function inherit(self, vararg)
{
for (i: #vararg - 1 .. -1)
{
// Go in reverse order so that more important things clobber weaker
// things.
schlep(self, vararg[i])
}
}
function schlep(self, add)
{
foreach (name, field; add.metadata)
{
self.name = field;
}
}
|
Is there a way of doing this in minid? I can do it with the MDClass / MDInstance stuff, though that won't be quite so elegant. |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Thu May 29, 2008 8:51 am Post subject: |
|
|
Are you using MiniD 1 or 2? The syntax you're using (like #vararg) says 2 but you're talking about classes and instances which are only in 1.
In either case, have a look at the fieldsOf and methodsOf functions in the base library. In MiniD 2 there is no methodsOf, and everything is accessible through fieldsOf.
Also, your for loop indices are off by one. Numeric for loops always treat the higher index as noninclusive and the lower as inclusive regardless of direction, so it'll just be "for(i: #vararg .. 0)". |
|
Back to top |
|
|
dhasenan
Joined: 03 Feb 2005 Posts: 73 Location: New York
|
Posted: Thu May 29, 2008 1:17 pm Post subject: |
|
|
I thought I grabbed the minid2 sources. Turns out I probably got the minid1 sources instead. Apparently they're sufficiently similar that most of what I've learned will still apply.
Thanks for your help. While most things are well documented, that adds up to a heap of documentation to wade through. I think I was expecting builtin stuff for reflection, but since there's a binding library, that makes a lot of sense.
This isn't explicitly mentioned in the docs, but I assume I can use the syntax "object.newField = value", where value can be a function or anything else, to add a method or field to an existing object, no? |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Thu May 29, 2008 3:05 pm Post subject: |
|
|
It actually is mentioned in the docs, here.
I will recommend, however, using MiniD 2 since that's where a lot of nice new functionality is. The native API is also a bit better and will be getting a lot better over the next couple of months. Though if you're worried about writing code for it now only to have it become outdated, you might want to stick to MD1 then.
[ed] you might already have the MD2 sources, if you checked out the entire repo. It's in branches/v2. |
|
Back to top |
|
|
dhasenan
Joined: 03 Feb 2005 Posts: 73 Location: New York
|
Posted: Thu May 29, 2008 4:09 pm Post subject: |
|
|
I do intend to use minid2. I've had some trouble testing stuff since my current computer has 64-bit Linux, precluding dmd, and the gdc I installed from the repositories has major issues, so I haven't been able to compile and run anything lately. This means I can't actually try minid2. |
|
Back to top |
|
|
dhasenan
Joined: 03 Feb 2005 Posts: 73 Location: New York
|
Posted: Thu May 29, 2008 6:18 pm Post subject: |
|
|
You say that classes and instances are only in minid 1, but they appear all over minid.bind in the v2 branch!
This of course makes it impossible to compile minid 2 at the moment, if I want to bind a class at least. |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Thu May 29, 2008 7:09 pm Post subject: |
|
|
minid.bind has not been updated to MD2. Don't use it. |
|
Back to top |
|
|
dhasenan
Joined: 03 Feb 2005 Posts: 73 Location: New York
|
Posted: Sun Jun 01, 2008 5:23 pm Post subject: |
|
|
Hm. If I can't use minid.bind, there can only be one way to proceed: I'll be writing the entire game in MiniD.
You claimed, I believe, that MiniD is faster than Lua, at least in some samples? If that holds in general, you're getting something like a tenth the speed of D, at least ignoring the object oriented aspects. And that makes MiniD probably one of the fastest scripting languages around.
Not sure it'll be fast enough to support the AI stuff I want to implement for ten or fifteen thousand NPCs, though... |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Mon Jun 02, 2008 12:11 am Post subject: |
|
|
In certain areas, it's faster than Lua. In others, not so much
I'm rewriting almost the entire interpreter for MiniD 2, though, after which minid.bind will be rewritten as well. All in all I expect the new implementation to be much faster. Lua speed? Not sure, but I can hope! |
|
Back to top |
|
|
Ligustah
Joined: 21 Oct 2007 Posts: 45 Location: Berlin, Germany
|
Posted: Thu Jun 05, 2008 4:15 am Post subject: |
|
|
dhasenan wrote: | Hm. If I can't use minid.bind, there can only be one way to proceed: I'll be writing the entire game in MiniD. |
Hi,
i recommend you to have a look at the minid/*lib.d files, where all the
standard API things are defined.
You'll see that you actually don't need minid.bind for exposing D functions
to MiniD, it's just more convenient.
Ligustah |
|
Back to top |
|
|
|