Table Index Matching in Luau
tracked
Ruby Maelstrom
Currently, when scripting in Luau, indexing of tables does not match between Luau functions and ll. functions.
For example, the following return the same values:
str = ll.List2String(List,2)
and
str = List[3]
This isn't exactly a bug, both are functioning 'correctly', but it's going to cause some issues. Is there a reasonable solution to this?
Log In
Signal Linden
tracked
This one's tricky. We'd like to keep most of these functions the way they are, because it makes it easier to do mechanical LSL source-> SLua source translation so people can rewrite their scripts as idiomatic SLua piecemeal. We have such a source->source translator in the works, it'll likely be released sometime after the alpha phase when we open-source the compiler and VM.
I think for most of these functions (like
llList2Key()
, etc, the answer is there's no good reason to use them in SLua, because their auto-casting behavior was always flaky, and explicit casting like uuid(some_tab[idx])
is less ugly.For functions that have no direct Luau equivalent, like
llListStatistics()
we'll eventually write proper Luau equivalents. Same goes for llDetected*()
and things that expect 0-based indices.Wulfie Reanimator
Can confirm. Mixing LSL calls and Lua loops is sure to cause headaches for years to come like this. As an example, here's a script that simply outputs keys of avatars in the region.
local AGENT_LIST_REGION = 4
local agents = ll.GetAgentList(AGENT_LIST_REGION, {})
ll.OwnerSay("Loop from 0 to list length")
for i=0, #agents, 1 do
ll.OwnerSay(`{i} {ll.List2Key(agents, i)}`)
end
-- 0 779e1d56-5500-4e22-940a-cd7b5adddbe0
-- 1
ll.OwnerSay("Loop by key-value pairs:")
for k,v in pairs(agents) do
ll.OwnerSay(`{k} {ll.List2Key(agents, k)}`)
end
-- 1
ll.OwnerSay("Loop by key-value pairs with Lua indexing:")
for k,v in pairs(agents) do
ll.OwnerSay(`{k} {agents[k]}`)
end
-- 1 779e1d56-5500-4e22-940a-cd7b5adddbe0