Hmm... It still says " unexpected symbol near ')' "
Although everything that people have said helped, it does not work :/
Lua help needed: How to get the lower boundary of a free table? See, you can get the upper boundary by table.maxn(), but, which I can't understand why, there's no table.minnn()
Example:
mtx={}
mtx[2]=1
mtx[-7]=42
table.maxn(mtx) --output:2
--how to get the -7?
The lua_gettop function returns the number of elements in the stack, which is also the index of the top element. Notice that a negative index -x is equivalent to the positive index gettop - x + 1.
Thanks for your reply
I found few documents, they say that, the table in lua act like this:
arr[k] is similar to normal array if k>0
Any situation else, arr[k] is similar to hash table
Did that means, m[{number}] is part of the array, but m[{Non-number}] is in the hash table part?
For example mtx: (in sequence)(pseudo code)
mtx={
'1':xxx
'2':xxx
...
'9999':xxx
'0'.getHash():xxxx
'-2'.getHash():xxxx (And they are ordered by the hash but not the 'key' itself)
}
So in my case, I can use the function below which you suggested instead:
function table.minn(t)
local min=0
for i in pairs(t) do
if type(i)=="number" and i<min then
min=i
endend
return min
end
BTW, I quit the free table idea already, it's not a good structure indeed. Using offset variable instead.