LuaArray - A JavaScript approach to arrays [Archive]

What is LuaArray?

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.

Documentation

Example

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.

Using Wally

[dependencies]
LuaArray = "alexinite/lua-array@0.1.2"

Documentation


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?

  • Yes
  • No

0 voters

4 Likes

If you like JavaScript and TypeScript over Luau, then you might be interested in learning roblox-ts.

1 Like

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.

1 Like

Yess I like this, but i only wish that it was like this

local array = new "array" [epic]

unfortunately its impossible unless you use another string which is bad and impractical, but good resource.

1 Like

Actually, this is possible, anyways this also doesn’t match with how arrays in JS work.

const array = new Array<number>(); // possible to an extent
// or
const array: number[] = []; // not possible in lua at all
1 Like

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.

LuaArray Abandonment

LuaArray has been abandoned in favor of LuaObjects