lua-users home
lua-l archive

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


Hi,


I'm new to lua (and I like it for the time being :)). For the time being I use it for processing of megabytes of raw binary data, which seems to work pretty well (I'm after performance so I'm quite happy I found lua :)).

As far as I know strings are 'non-changeable' in lua (I mean if you want to change it you always end up creating a new string). I usually follow others' example by reading entire binary file contents into variables, then interpreting/processing them. So I end up using pretty long strings. :)

In C/C++ it's very efficient to pass variables/data by reference (where you don't pass and therefore duplicate the data itself, just pass a reference to it). I don't know the exact parameter-passing system of lua, and I want to avoid situations where megabytes of data is being duplicated just because of passing it to a function.

So, my question is, how variables (especially strings) passed to functions internally? (Are they referenced or duplicated) Is it possible to pass by reference in general? (I know I could use global variables as an option for that, but I'm trying to follow the 'being as local as possible' rule :) so I always use local variables.)

Anyone could shed some light for me? :)



imre



--
[ Imre Tuske | http://... | mailto:imre.tuske@gmail.com ]