Safely remove items from an array table while iterating

the general case of iterating over an array and removing random items from the middle while continuing to iterate If you’re iterating front-to-back, when you remove element N, the next element in your iteration (N+1) gets shifted down into that position. If you increment your iteration variable (as ipairs does), you’ll skip that element. There … Read more

How to read data from a file in Lua

Try this: — http://lua-users.org/wiki/FileInputOutput — see if the file exists function file_exists(file) local f = io.open(file, “rb”) if f then f:close() end return f ~= nil end — get all lines from a file, returns an empty — list/table if the file does not exist function lines_from(file) if not file_exists(file) then return {} end local … Read more

Function/variable scope (pass by value or reference?)

You guessed right, table variables are passed by reference. Citing Lua 5.1 Reference Manual: There are eight basic types in Lua: nil, boolean, number, string, function, userdata, thread, and table. …. Tables, functions, threads, and (full) userdata values are objects: variables do not actually contain these values, only references to them. Assignment, parameter passing, and … Read more

What is a good game engine that uses Lua? [closed]

Game engines that use Lua Free unless noted Agen (2D Lua; Windows) Amulet (2D Lua; Window, Linux, Mac, HTML5, iOS) Cafu 3D (3D C++/Lua) Cocos2d-x (2D C++/Lua/JS; Windows, Linux, Mac, iOS, Android, BlackBerry) Codea (2D&3D Lua; iOS (Editor is iOs app); $14.99 USD) Cryengine by Crytek (3D C++/Lua; Windows, Mac) Defold (2D Lua; Windows, Linux, … Read more