Advanced

TableRemove return value

TableRemove return value
January 10, 2018 10:48AM
Quote

table.remove (table [, pos])

Removes from table the element at position pos, shifting down other elements to close the space, if necessary. Returns the value of the removed element. The default value for pos is n, where n is the length of the table, so that a call table.remove(t) removes the last element of table t.

For some reason TableRemove seems to return nil instead of the removed value.
Re: TableRemove return value
January 10, 2018 05:06PM
I wonder if this could be a bug in LUA or something that has changed over the versions. The Sandbox doesn't control what it returns, there is only an associative list of functions that should be included/allowed. Like:
TableMaxn = table.maxn,
TableRemove = table.remove,
TableSort = table.sort,

The LUA version that is currently being used is 5.1.5.

Since I am not used to LUA at all anymore, if I ever was. If you write a short LUA snippet that I can test in CLI I can run it directly on the server. Something like:
Add to table
Add to table
Add to table
removed = Remove from table
print(removed)
Re: TableRemove return value
January 10, 2018 05:34PM
Very interesting, now it works :)

Earlier I had to write
local item = queue[#queue]
TableRemove(queue)
to avoid some nil reference error instead of
local item = TableRemove(queue)
But now it works with a single line as it should. And this happened twice with different code ::o
Maybe my change did not fix anything and the error was somewhere else.
Sorry, you do not have permission to post/reply in this forum.