lua-users home
lua-l archive

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


HI, when write lua code, I want to set the table capacity before I use it, so it can reduce the rehash times.
such as the code below
the 't' array size maybe [0, 100]
local t = {}
for t in string.gmatch(str, "%w+") do
t[#t + 1] = k
end

I know the lua_createtable can do this thing, but it will call C function.
so is the possible add some support in lua?

local t = {(100, 0)} -- give t 100 array capacity
for t in string.gmatch(str, "%w+") do
t[#t + 1] = k
end