webmcp

changeset 495:7eec5b604b00

Provide custom implementation of table.insert for Lua 5.2
author jbe
date Fri Jun 30 17:01:04 2017 +0200 (13 months ago)
parents e7c9a80b6795
children 3b4dbabca31f
files framework/env/__init.lua
line diff
     1.1 --- a/framework/env/__init.lua	Wed Jun 28 18:51:36 2017 +0200
     1.2 +++ b/framework/env/__init.lua	Fri Jun 30 17:01:04 2017 +0200
     1.3 @@ -54,6 +54,29 @@
     1.4  end
     1.5  --//--
     1.6  
     1.7 +--[[--
     1.8 +table.insert(
     1.9 +  t,           -- table
    1.10 +  index,       -- optional index
    1.11 +  value        -- value
    1.12 +)
    1.13 +
    1.14 +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).
    1.15 +
    1.16 +--]]--
    1.17 +do
    1.18 +  local old_insert = table.insert
    1.19 +  function table.insert(...)
    1.20 +    if _VERSION == "Lua 5.2" and select("#", ...) == 2 then
    1.21 +      local t, value = ...
    1.22 +      t[#t+1] = value
    1.23 +      return
    1.24 +    end
    1.25 +    return old_insert(...)
    1.26 +  end
    1.27 +end
    1.28 +--//--
    1.29 +
    1.30  -- load libraries
    1.31  -- (except "extos", which has to be loaded earlier, and "multirand", which must be loaded after forking)
    1.32  _G.nihil       = require 'nihil'

Impressum / About Us