Missing information for documentation of lots of globals

image

ipairs documentation doesn’t mention it also returns zero.

pairs has been changed in Roblox, and it doesn’t return next. It should also mention that it returns nil as a third value. pairs does not only work with arrays, so it should say table instead of array.

next doesn’t work with only arrays, so it should say table instead of array.

assert uses the errorMessage argument when the assertion fails. All values are returned when the assertion passes, not just the first argument.

getfenv is not guaranteed to return array, it should say table instead of array. As mentioned, stack doesn’t have to be an integer, and can be a function, so it should be listed as Variant.

In Roblox, print doesn’t use the tostring function, but does check __tostring.

image

select also works with a negative index. (index -1 gets the last argument from args, index -2 gets the last 2 arguments from args, …)

It should be mentioned that the string must be the octothrope to get the number of arguments passed after cmd, and that using anything else will cause an error. (could the two descriptions of select be merged?)

setmetatable doesn’t only work for arrays, it should say table instead of array.

fenv doesn’t have to be an array, it should say table instead of array.

The optional chunkname argument isn’t mentioned. (default is contents)

t doesn’t have to be an array, it should say table instead of array.

t doesn’t have to be an array, it should say table instead of array.

I think it should be mentioned that with base 10 hexadecimal numbers will also be interpreted.

In standard Lua tostring must return a string, but in roblox this isn’t the case. (this might be a bug?)

2 Likes

Thanks for pointing out these inaccuracies! I’ve went ahead and corrected (almost) all of them and added some useful examples :slight_smile:

I wasn’t entirely sure what you meant by loadstring’s chunkname argument. I couldn’t find any information on this either, do you have a source or example?

Source: https://www.lua.org/manual/5.1/manual.html#pdf-loadstring
image
Its used when generating debug info.

1 Like

Another thing, under getfenv there is an example of getting the enviroment based on the stack, but a local is used and the stack index is wrong.
A better example would be

function whatIsThePassword()
	local env = getfenv(2) -- Get the environment 1 level up, or whatever called this function
	print(env.password) -- Get the password from the environment one level up
	print(password) --> nil
end
function openSesame()
	password = "secret" -- A variable local to openSesame since enviroment was set
	whatIsThePassword()
end
setfenv(openSesame,{whatIsThePassword=whatIsThePassword})
openSesame()

Whoops. I was futzing around with the command bar when I wrote that example. I’m not sure if there’s a simpler example that just uses getfenv here, so I’m wondering if I should nix the example entirely.

I was wrong with saying print doesn’t call tostring, could this be updated?

function tostring(x)
    return "a"
end
print(nil) --> a

Although you might want to specify that it will get global tostring so the behavior can be changed by changing the global tostring.