[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Feature request: names for constants
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 24 Sep 2015 13:11:01 -0300
> local trim_pattern = "^%s*(.*%S)%s*$"
This already does exactly what you want.
The only cost is one local and one instruction, which get executed only once,
unless you have this inside a loop (in which case, you may move it out).
Almost all instructions in the Lua VM accept a register or a constant.
The few that don't but could are:
local x; function f() x=2 end
It appears that none of these are at all common, except perhaps OP_SETUPVAL,
and OP_LEN for string constants.
Bottom line: there isn't a problem that needs to be solved by adding a syntax
for constants. The parser might be smart and use the constant's index instead
of the local's index, but they are both just an array access in the VM.