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

toJSON api function

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



Joined: 21 Oct 2007
Posts: 45
Location: Berlin, Germany

PostPosted: Mon Oct 29, 2007 6:46 pm    Post subject: toJSON api function Reply with quote

Hi!
I'm missing a toJSON function in the MiniD api. I need it for saving some information about my scripts. I want my scripts to have these information, so i load them from a table out of a file. For saving this table i need something like toJSON in the api.

Mfg Ligustah
Back to top
View user's profile Send private message
JarrettBillingsley



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

PostPosted: Mon Oct 29, 2007 9:10 pm    Post subject: Reply with quote

Another good idea. In the meantime you can do the following:

Code:

MDString toJSON(T)(MDState s, T r)
{
   static if(is(T : MDTable) || is(T : MDArray))
      alias r root;
   else
      MDValue root = r;

   s.easyCall(s.context.globals["toJSON"d], 1, MDValue(null), root);
   return s.pop().to!(MDString);
}

// Use like this:
MDTable t = MDTable.create
(
   "foo", "bar",
   "baz", 5,
   "array", MDArray.create(1, 2, 3.4)
);

Stdout.formatln("{}", toJSON(ctx.mainThread, t));
Back to top
View user's profile Send private message
Ligustah



Joined: 21 Oct 2007
Posts: 45
Location: Berlin, Germany

PostPosted: Tue Oct 30, 2007 5:31 am    Post subject: Reply with quote

Thx. Looks quite simple. I'll use it, waiting for a real toJSON api function Razz

Mfg Ligustah
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