Ludicrous Software

table_AS3: AS3 Array Methods for Lua

Inspired by the comment in Dave Fulton’s blog post comparing the AS3 to Lua that many of the methods of AS3’s Array class aren’t available in Lua, I’ve created a Lua module that ports those methods to Lua.

You can grab the code on GitHub. It includes a sample main.lua that will show you how to use the functions, but if you’re familiar with AS3’s Array methods, then you can probably skip that altogether.

If you are familiar with the Array class, then there are a few things you’ll still need to remember:

  • I’ve renamed Array.concat to table.concat_as3, to avoid conflict with Lua’s built-in table.concat method.
  • Since tables in Lua are 1-based, wherever you’d see a 0 in the docs for the Array class, just substitute a 1.

The library does some basic error checking (e.g. to make sure you’re calling the method on an actual table), and will use the same default values as the Array methods for optional parameters.

If you catch any bugs, or if there are any other Array methods you think should be added to the library, let me know in the comments!