lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


D. Burgess is correct about using luaL_loadbuffer().

The first line in the string, however, should be changed from "local
treeInfo =" to "return".

-KB

> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br 
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of D Burgess
> Sent: Saturday, May 01, 2004 1:00 AM
> To: Lua list
> Subject: Re: string as Lua-data
> 
> 
> use
> 
> int  luaL_loadbuffer (lua_State *L, const char *buff, size_t sz,
>                                 const char *name);
> 
> see auxlib.h
> and see auxlib.c for examples of its use. e.g. lua_dobuffer
> 
> 
> Michaela Kyavar <michaela.kyavar@gmx.de> wrote:
> 
> >Hello!
> >
> >I've created in C the following string representing data in Lua form:
> >
> >"
> >local treeInfo =
> >     {name = "ROOT", type = "t1", numSubs = 1, subs = {
> >          {name = "n2", type = "t2", numSubs = 10, subs = {
> >               {name = "n3", type = "t3", numSubs = 0, subs = {}},
> >               {name = "n4", type = "t4", numSubs = 0, subs = {}},
> >               {name = "n5", type = "t5", numSubs = 0, subs = {}},
> >               {name = "n6", type = "t6", numSubs = 0, subs = {}},
> >               {name = "n7", type = "t7", numSubs = 0, subs = {}},
> >               {name = "n8", type = "t8", numSubs = 0, subs = {}},
> >               {name = "n9", type = "t9", numSubs = 0, subs = {}},
> >               {name = "n10", type = "t10", numSubs = 5, subs = {
> >                    {name = "n11", type = "t11", numSubs = 
> 1, subs = {
> >                         {name = "n12", type = "t12", 
> numSubs = 3, subs = {
> >                              {name = "n13", type = "t13", 
> numSubs = 0, subs
> >= {}},
> >                              {name = "n14", type = "t14", 
> numSubs = 1, subs
> >= {
> >                                   {name = "n15", type = 
> "t15", numSubs = 0,
> >subs = {}}}},
> >                              {name = "n16", type = "t16", 
> numSubs = 2, subs
> >= {
> >                                   {name = "n17", type = 
> "t17", numSubs = 0,
> >subs = {}},
> >                                   {name = "n18", type = 
> "t18", numSubs = 1,
> >subs = {
> >                                        {name = "n19", type 
> = "t19", numSubs
> >= 0, subs = {}}}}}}}}}},
> >                    {name = "n20", type = "t20", numSubs = 
> 0, subs = {}},
> >                    {name = "n21", type = "t21", numSubs = 
> 0, subs = {}},
> >                    {name = "n22", type = "t22", numSubs = 
> 0, subs = {}},
> >                    {name = "n23", type = "t23", numSubs = 
> 0, subs = {}}}},
> >               {name = "n24", type = "t24", numSubs = 0, subs = {}},
> >               {name = "n25", type = "t25", numSubs = 0, 
> subs = {}}}}}}
> >"
> >
> >
> >This is a C-string, but has the exact representation of 
> nested Lua tables.
> >
> >My question is:  Is there a "cool" way to easily create a 
> Lua initialized
> >table variable out of this, i.e. convert from the string 
> representation to a
> >Lua representation?
> >
> >Of course I could write the data to a file, exactly as 
> above, and read it in
> >through the interpreter as a Lua variable.
> >Is there a way to do this without resorting to writing / 
> reading files?
> >File access is too slow for our purposes.
> >
> >Thankyou,
> >M
> 			
> 
> 
>