lua-users home
lua-l archive

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


On Mon, Jun 15, 2009 at 4:41 PM, Sivan Thiruvengadam<rajskm@gmail.com> wrote:
> Hi,
> I am using LUA on Handheld Pocket PC based device. When i try to load a file
> which has around 500 local variables, the lua loadfile function throws the
> above error?
>
> PS: I am providing a sample of the code here.
>
> local GUIERRORBASE  = 5000
> -- Common Error Returned By BRSTK
> local BRSTK_VALIDATION_SUCCESS = 0
> local BRSTK_VALIDATION_FAILURE = GUIERRORBASE+1001
> local BRSTK_SCAN_NOT_FOUND = GUIERRORBASE+1002
> local BRSTK_FIELD_NOT_FOUND = GUIERRORBASE+1003
> local BRSTK_LABEL_NOT_FOUND = GUIERRORBASE+1004
> local BRSTK_INVALID_SERVICE_XML = GUIERRORBASE+1005
> local BRSTK_INVALID_CATALOG_XML = GUIERRORBASE+1006
> local BRSTK_VALIDATOR_LOAD_FAILURE = GUIERRORBASE+1007
> local BRSTK_SERVICE_NOT_INITED = GUIERRORBASE+1008
> local BRSTK_MEMORY_ALLOC_ERROR = GUIERRORBASE+1009
> local BRSTK_VALIDATOR_NOT_FOUND = GUIERRORBASE+1010
> local BRSTK_END_OF_FILE = GUIERRORBASE+1011
> -- It goes like this for 500 variables.

Local variables are a limited resource. Due to the structure of the VM
bytecode, and a few other things, a function cannot have more than 256
local variables. In practice, the limit is reduced down to 200, though
it can probably be raised to 240 or 250 without too many issues. Local
variables are intended to be variables though, not named constants. I
would suggest either placing the constants into a table, or modifying
the parser to accept named constants in a way similar to C's "#define
CONSTANT value".