FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Setting attributes with the API

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
vektorboson



Joined: 14 Sep 2006
Posts: 44

PostPosted: Thu Dec 17, 2009 5:10 pm    Post subject: Setting attributes with the API Reply with quote

I'm using the attribute-functionality in MiniD to create DocStrings (as in the BaseLib-documentation).
I tried to create a doc-attribute within the API and this is my solution:

Code:

...
import minid.api;
import minid.baselib;
...

void createDocString(MDThread*t, char[] funcname, char[] docstring) {
        pushGlobal(t, funcname);
       
        newTable(t, 1);
        pushString(t, docstring);
        fielda(t, -2, "doc");
        BaseLib.attrs(t, 2);

        pop(t);
    }


I'm using it like this:
Code:

    newFunction(t, &terminateApplication, "quit");
    newGlobal(t, "quit");
    createDocString(t, "quit", "terminates the application");


Hopefully this is useful to someone (or maybe something similar will be included in MiniD itself).
Back to top
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Mon Jan 25, 2010 6:50 am    Post subject: Reply with quote

Wow, somehow I managed to miss your threads for over a month. I think I've been depending on the "new posts" feature of the forums too much!

I've actually considered adding a "doc" decorator or so to the standard library, which would basically do exactly what your function does Smile I haven't decided though whether or not it should use the attribute tables, since someone might do this:

Code:

@attrs$ { x = 5 }
@doc$ "This is a docstring!"
function foo() {}


and oops, the @attrs call overwrites the existing table created by the @doc call. It could special-case for this but bleeeeh. So it might store the docstrings somewhere else X)

I'd also like to add a minid.ex API for creating functions with docstrings, much like what's available in the CPython API, so that you could do something like:

Code:

newFunction(t, &foo, "foo", "This function does something stupid.");
Back to top
View user's profile Send private message
vektorboson



Joined: 14 Sep 2006
Posts: 44

PostPosted: Mon Jan 25, 2010 11:05 am    Post subject: Reply with quote

JarrettBillingsley wrote:

I'd also like to add a minid.ex API for creating functions with docstrings, much like what's available in the CPython API, so that you could do something like:

Code:

newFunction(t, &foo, "foo", "This function does something stupid.");


That would be nice!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group