Google

main
dspblog
cyclic_signals
FFT_interpolation
FFT_interpolation_how_does_it_work
FFT_smoothness_cyclic
discrete_time_reconstruction
discrete_time_reconstruction2
Nyquist_on_the_edge
FFT_delay_special_case
Fourier_reconstruction
pulse_and_Nyquist
FFT_complexError
matlabOctave
matlab_upsampling
matlab_downsampling
FFT_delay
FFT_filter_example
FFT_interpolation_example
FFT_bin_frequencies
fit_signal
FFT_peaksearch_audio_example
matlab_binary_readwrite
Octavesvg
C
FFTW_example
looprecord
SNR
SNR3
SNR_example_96kAudio
SNR_FFT_correlation_example
lua
luagpib
luasplit
luadump
mnoofltk
wxLuaDll
wxLua_loadAsDll
wxLua_HelloWorld
wxLua_simpleButton
wxLua_resourceManagement
wxLua_XMLparser
DSP
IQ_LO
IQ_LO_2
optimum_receiver
DSP_basics
sampleRateChange_terms
dirac_pulse
freqresp_s
zfilter_example
freqresp_z
freqresp_z_sign
misc
zero_forcing_equalizer_example
nonminphase_inverse
periodic_spectrum
lagrange_multipliers
Entropy
RC_chopper
TRex450_setup
EP100
EP100SE
EP100Gremlins
essential_spares
tail_rotor
motoradjustment
blade_balancing
blade_repair
GAUI_SAE12A
Walkera43


valid html (click to verify)



prevupnextdisable ads

Serialize nonrecursive data structure

Summary

A function that produces lua code from a data structure.
When executed, the code returns a copy of the data structure.
The function is quite useful for quick application development, since one does not need to write "save" and "load" code.
Since it uses the lua interpreter itself for parsing the results, it loads even large datasets quickly.
It is also very useful for debugging, since the serialized data structure can be dumped to screen or file.

Example

dumpStructure=require('dumpStructure')
t={"one", "two", "three", {"four"}, t1={1, 2, 3}}
print(dumpStructure(t))


returns

{"one","two","three",{"four"},["t1"]={1,2,3}}

Download

here

Code

-- ##########################################################################
-- # dump() function for lua
-- # Markus Nentwig 2007
-- # This code is in the public domain and provided without any warranty.
-- #
-- # Serializes a table tree structure (non-recursive)
-- # executing "return "..dump(struct) reconstructs the structure.
-- ##########################################################################
local dump
dump=
   function(a)      
      local t=type(a)
      if t=="nil" then 
	 return "nil"
      elseif t=="number" then
	 return tostring(a)
      elseif t=="string" then
	 return string.format("%q", a)
      elseif t=="table" then
	 local res={}
	 -- do itable part
	 local done={}
	 for key, val in ipairs(a) do
	    table.insert(res, dump(val))
	    done[key]=true
	 end
	 for key, val in pairs(a) do
	    if not done[key] then
	       table.insert(res, "["..dump(key).."]="..dump(val))
	    end
	 end
	 return "{"..table.concat(res, ",").."}"
      else
	 error("invalid type "..(t or "?"))
      end
   end
return dump


prevupnextdisable ads

© Markus Nentwig 2007-2008
The content of this page is provided without any warranty and may not be reproduced without permission.

Comments? Questions?

Please send me a mail! mnentwig@elisanet.fi