lua-users home
lua-l archive

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


On Mon, May 21, 2012 at 7:27 AM, Maha Akkari <maha.akkari@gmail.com> wrote:
> I am integrating Network Simulator 3 and Lua.
>
> I wrote a Mobile File in Lua script. that file will go on the network, visit
> certain nodes and collect information from them.
>
> The problem I am facing is that dont know how to keep the information that
> was collected from the nodes,  i.e. I dont know how to save that information
> I am getting in the variables of Luascript !!!
>
> let me explain , for simplicity reasons, say my MobileAgent.lua script
> initially  contains :
>
> array1 ={"10.10.2.3", "10.10.4.3"}
>
> array2={ ip1="10.2.3.4", ip2="10.3.2.4"}
>
> function update_array1 (t)
>   (some code )
> end
>
> function update_array2 (t)
>   (some code )
> end
>
>
> So remember, my MobileAgent.lua will travel to some nodes on the network and
> update the arrays.
> say MobileAgent.lua has to visit node1 ,node2 and node3.
>
> so first, the file arrives at node 1.
> node1 calls the script and add the element "255.255.255.0" to both arrays.
>
> What I want it for the MobileAgent.lua to look like this :
>
> array1 ={"10.10.2.3", "10.10.4.3" , "255.255.255.0"}
>
> array2={ ip1="10.2.3.4", ip2="10.3.2.4", ip3="255.255.255.0"}
>
> function update_array1 (t)
>   (some code )
> end
>
> function update_array2 (t)
>   (some code )
> end
>
>
> then, MobileAgent.luav  arrives at node 2
> node2 calls the updated script and add the element "255.255.255.2" to both
> arrays.
>
> so MobileAgent.lua should look like this :
>
> array1 ={"10.10.2.3", "10.10.4.3" , "255.255.255.0","255.255.255.2"}
>
> array2={ ip1="10.2.3.4", ip2="10.3.2.4", ip3="255.255.255.0", ip4=
> "255.255.255.2"}
>
> function update_array1 (t)
>   (some code )
> end
>
> function update_array2 (t)
>   (some code )
> end
>
>
> I was able to successfully  pass the arrays to the C ++ code in the node, an
> that node updates them, pushes them on the stack, lua takes them from the
> stack and update the array in memory, but i dont know how to WRITE those on
> the lua script itself in the right place !
>
> Kindly note that I have more than 2 arrays and some associative arrays in my
> script. but i gave that example for simplicity reasons.
>
>
> Any idea what I can do in lua to achieve what I want ? its very urgent !!
> And nobody has asked this question in ANY of the lua forums, so i couldnt
> find and help. is it doable in lua in the first place :s ???  thank you .

You want to read in, modify, and write back the Lua script that
defines these tables? That seems error-prone. Perhaps a better idea is
to append? Your script would look like:

array1, array2 = {}, {}
array1[1] = "10.10.2.3"
array2["ip1"] = "10.2.3.4"
array1[2] = "10.10.4.3"
array2["ip2"] = "10.3.2.4"

Then updating to add new addresses would just mean appending similar
lines to the end of the file.

-- 
Sent from my Game Boy.