View previous topic :: View next topic |
Author |
Message |
vertex
Joined: 24 Nov 2007 Posts: 18
|
Posted: Mon Nov 26, 2007 3:09 pm Post subject: New to MiniD / Question about namespaces |
|
|
First of all ... congratulations. I've been looking for a scripting language for my project for a long time, and MiniD is very groovy (kinda miss a behave() function though, don't know why ). Especially the tight integration with D, the exceptions and the GC is great. The "flow" from native to script and back is really seamless.
Now to my question: I want to export some functions from native code to my scripts and group them into categories. I thought namespaces were the way to go ... but I can't figure out how to add MDClosures to a namespace. Adding a global namespace is no problem, but ...
namespace["test"d] = new MDClosure(namespace, &test, "test");
... doesn't compile and ...
new MDClosure(namespace, &test, "test");
... does (obviously) not work. I think I'm missing something obvious here. Alternatively: Is there a way to create static members for classes? I didn't find anything in the docs on that.
-Mike |
|
Back to top |
|
|
vertex
Joined: 24 Nov 2007 Posts: 18
|
Posted: Mon Nov 26, 2007 3:39 pm Post subject: The obvious ... |
|
|
... is MDValue's static opCall |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Mon Nov 26, 2007 3:50 pm Post subject: |
|
|
Quote: | First of all ... congratulations. I've been looking for a scripting language for my project for a long time, and MiniD is very groovy (kinda miss a behave() function though, don't know why Very Happy ). Especially the tight integration with D, the exceptions and the GC is great. The "flow" from native to script and back is really seamless. |
Quote: | MDValue's static opCall |
Indeed
Quote: | Is there a way to create static members for classes? |
Nope. What's kind of odd though is that you can call methods of classes through the class, and the class will be passed as the 'this' to the method. In that way you can fake static methods, but those methods will also be available through the instances of that class, which could be a problem.
Static fields and methods is something I'm considering for MD2. |
|
Back to top |
|
|
vertex
Joined: 24 Nov 2007 Posts: 18
|
Posted: Mon Nov 26, 2007 4:32 pm Post subject: |
|
|
JarrettBillingsley wrote: |
Nope. What's kind of odd though is that you can call methods of classes through the class, and the class will be passed as the 'this' to the method. In that way you can fake static methods, but those methods will also be available through the instances of that class, which could be a problem.
Static fields and methods is something I'm considering for MD2.
|
Static fields would be nice indeed. It's great that you're planning to support such things in the future. I'm playing with MiniD since yesterday and getting more impressed by the minute - it's an external library that's fun to link against! And it just works! You don't see that often. Too bad that I need to hold a seminar tomorrow
Another thing: I want to replace writef/etc. with my own output functions (there's only one class in my program that is allowed to write to the console - it's a little command line editor and I need to update the prompt every new line). Is it okay to just hack baselib.d and replace the calls to Stdout?
-Mike |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Mon Nov 26, 2007 5:06 pm Post subject: |
|
|
Quote: | Another thing: I want to replace writef/etc. with my own output functions (there's only one class in my program that is allowed to write to the console - it's a little command line editor and I need to update the prompt every new line). Is it okay to just hack baselib.d and replace the calls to Stdout? |
Either that, or you could write your new functions and just reassign the globals write[f][ln] to new function closures, like:
Code: | writefln = function(vararg)
{
myStream.writefln(vararg);
}; |
You could do it with native closures too, of course. |
|
Back to top |
|
|
vertex
Joined: 24 Nov 2007 Posts: 18
|
Posted: Tue Nov 27, 2007 2:27 pm Post subject: Perfect! |
|
|
And thanks for the fast response! |
|
Back to top |
|
|
|