lua-users home
lua-l archive

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


David Manura wrote:
On another point, I think it's inconsistent that Lua's VM has an
opcode to obtain the length in bytes of a string (i.e. # s), but
there's no opcode to obtain the i-th character or byte of a string
(e.g. s[i]).

I thought the same originally, but unfortunately I believe it's the best as is. Otherwise it seems quite inconsistent that they can be indexed read, but not written:

local a = "hello"
assert(a[1] == "h")
a[1] = "b"

Besides, any jiter should inline the call. (and luajit 2.x may even do a good job of avoiding the :str lookup).

(Unrelated though, but something I'd like to see in jit 2.x would be things such as "if str:sub(1, 2) == "__" then" remove the string creation and just compare the first two bytes - just because it's a fairly common operation in my code at least).

- Alex