lua-users home
lua-l archive

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


> Alas, I do need. Haven't done a lot of C programming and and haven't got my
> head around the lua C api yet...

So, it's probably much easier to do it in Lua. The "load" function also
accepts a reader function. Try something like this (tested!):

function loadcvs(f)
 local state=1
 local r=function ()
  if state==1 then state=2 return "return {" end
  if state==2 then
   local l=f:read()
   if l then return "{ "..l.." }," else state=3 return "}" end
  end
  if state==3 then return nil end
 end
 return assert(load(r))()
end

local f=io.open"j"
local b,e=loadcvs(f)
for K,V in next,b do
 for k,v in next,V do print(k,v) end
 print""
end