lua-users home
lua-l archive

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


Hi.

procedure LuaToXML(L : PLua_State; TableIndex : Integer; LoadInto :
TXMLItem);
begin
  LoadInto.Name  := LuaGetTableString(L, TableIndex, 'Name');
  LoadInto.Text  := LuaGetTableString(L, TableIndex, 'Text');
  LoadInto.CData := LuaGetTableString(L, TableIndex, 'CData');

  lua_pushnil(L);
  lua_pushstring(L, 'Params');
  lua_gettable(L, TableIndex);
  LoadInto.Params.Clear;

    // You forgot to push nil =)
    lua_pushnil(L);
  while (lua_next(L, -2)<>0) do
    begin
        // Avoid using lua_tostring here because it can change the
        // value on the stack when the value is a number (thus, breaking
        // lua_next behavior)
// LoadInto.Params.Values[LuaToString(L, -2)] := LuaToString(L, -1);

	if lua_isnumber(L, -2) then
            LoadInto.Params.Values[FloatToStr(lua_tonumber(L, -2))]:=
                lua_tostring(L, -1)
        else if lua_isstring(L, -2) then
            LoadInto.Params.Values[lua_tostring(L, -2)]:=
                lua_tostring(L, -1)
        else
            raise Exception.Create('duh');

      lua_pop(L, 1);
    end;
end;

(Again, not tested ;))

--rb