Originally Posted by Vladinator
Just trying to figure out what is best or commonly acceptable. I am a bit uncertain since you can use a variable and save a int or a table in it, it's not like C where you can assign so many bytes then all the data you use is the same size or less, so that way it saves performance because it doesn't have to reallocate space all the time, while in lua the data sizes vary so much that I wonder if it helps at all having the locals at start, or if it doesn't mater if they are inside the loops and what not.
|
If you're coming at this from a C background, then the answer is: Lua draws a sharper distinction between
variables and
values than what you may be used to.
- All variables are the same size. Values are of different sizes.
- Most variables have names. Values never do, not even functions.
- Variables themselves have no type. Values always have a single strong type (but some values can be implictly coerced to other types, which makes the type system look weaker than it really is). The "type(var)" function tells you what the type of the value
held by the variable is.
- Variables refer to values. Specifically, variables hold simple types (nil, numbers, booleans, etc) internally, and hold a pointer to object types (tables, strings,
functions etc).
- [Re-]assigning values to variables can be done at any time to any combination of variables and values. Size doesn't matter, honest!
Also a question about lua formatting, is there some tool to help reformat a whole file of code? Let's say you got a big file and the new lines messed up so all is now in one line...
|
If it's only the line endings, then any good text editor should be able to both (a) figure out what the current ending is and adjust its display accordingly, and (b) let you specify what ending to use when saving the file.
If it's more then the line endings, you might try good old GNU Indent and its reformatting modes.