# HG changeset patch # User jbe # Date 1498834864 -7200 # Node ID 7eec5b604b00119a03a26ce3b603a54e6c50223e # Parent e7c9a80b6795ef4e325c3a4ca332efb4e34d067c Provide custom implementation of table.insert for Lua 5.2 diff -r e7c9a80b6795 -r 7eec5b604b00 framework/env/__init.lua --- a/framework/env/__init.lua Wed Jun 28 18:51:36 2017 +0200 +++ b/framework/env/__init.lua Fri Jun 30 17:01:04 2017 +0200 @@ -54,6 +54,29 @@ end --//-- +--[[-- +table.insert( + t, -- table + index, -- optional index + value -- value +) + +Custom implementation of Lua's table.insert(...) where table.insert(table, value) also respects metamethods in Lua 5.2 (this behavior is already supported by Lua 5.3). + +--]]-- +do + local old_insert = table.insert + function table.insert(...) + if _VERSION == "Lua 5.2" and select("#", ...) == 2 then + local t, value = ... + t[#t+1] = value + return + end + return old_insert(...) + end +end +--//-- + -- load libraries -- (except "extos", which has to be loaded earlier, and "multirand", which must be loaded after forking) _G.nihil = require 'nihil'