lua-users home
lua-l archive

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

Imre Tuske wrote:

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.

Lua always passes by value, but the "values" of functions,
strings, tables, threads, and userdatas are just references
to the part that varies in size.  In the case of strings,
this means that what you suspected is true: when a function
receives a string as an argument, it receives a reference to
the location of the string's contents, and no character-by-
character copy of the string is made.

Not only this, but if you read two files with identical
contents into strings, the same string will be used.  (This
is why strings need to be immutable.)

I believe there's no case where Lua itself copies data of
indefinite size (strings, tables, etc.).

Beginning Lua Programming: