[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- 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:
OP_SETUPVAL
local x; function f() x=2 end
OP_UNM
x=-"2"
x=-true
OP_BNOT
x=~"2"
x=-true
OP_LEN
x=#2
x=#"hello"
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.