LuaArray is an implementation of arrays from JavaScript. There are some things not included, a list of methods are here.
LuaArray depends on my other module LuaClass, but don’t worry about importing it as it will bundle itself with LuaArray if you’re not already using it.
local new = require(game.ReplicatedStorage.Packages.LuaClass)()
local array = new "Array" (5, 12) -- [5, 12]
local newLength = array.push(7) -- 3
local mappedArray = array.map(function(num: number)
return num * 2
end) -- [10, 24, 14]
print(mappedArray[2]) -- 24
if mappedArray.includes(10) then
print(mappedArray.indexOf(10)) -- 2
end
Installing LuaArray
LuaArray is available via Wally and expects you to be using a Rojo workflow. If you rather download it from GitHub you can get the .zip file from its source.
I’m thinking of at some point bundling LuaArray, LuaClass, Import, (future JS/TS implementations here) into a single resource, would you be interested in that?
I know how to use roblox-ts and I am quaint with it. These aren’t made to make roblox-ts irrelevant and instead just an extension to what Roblox gives us with Luau instead of having to overwhelm people to learn an entirely new programming language for singular features that they would like to implement.
I don’t think its worth sacrificing performance over small syntax change, if someone really dislikes Luau syntax they should consider making/using transpiler or just switching to different/their own game engine. But good job on module.
I understand your pick on LuaClass, which is internally used and is mainly there for syntax, however with the innerworkings of LuaArray I wouldn’t necessarily agree as LuaArray offers way more builtin functions than Lua’s table.
If you’d like, I could create a version of this that doesn’t use my LuaClass.
My one question to you is. Why.
Lua’s best & most flexible feature is tables, by restricting it to this Array wouldn’t you be taking away that flexibility?
Edit: I replied to the wrong fella, was meant to reply to @alexinite
Sometimes offering this flexibility is more of a hassle, as then you have to create your own ways of interfacing with tables. However, if you’re using an array and only need the generic methods there’s no reason to have to interface it yourself as the methods are already builtin.
To me lua’s focus point is tables, it’s highlighted feature, etc.
If you didn’t want to handle the flexibility of lua tables, then why are you using lua? Wouldn’t another language such as the one you’re imitating be a better language for that person?
even when it comes to your documentation you just direct them to a JavaScript demo, this doesn’t add a significant resource and only limits what players can do with tables…?
If you were to produce a library to add to what Roblox’s table global already does, then I can see that as being more useful.