[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: string as Lua-data
- From: "Michaela Kyavar" <michaela.kyavar@...>
- Date: Sat, 1 May 2004 11:27:11 +0200
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