webmcp

changeset 64:3d43a5cf17c1

Compatibility with Lua 5.2
author jbe
date Sun Apr 15 16:04:33 2012 +0200 (2012-04-15)
parents 4f38db8354b0
children a54cc7dcabf1
files framework/accelerator/webmcp_accelerator.c framework/bin/autodoc.lua framework/bin/langtool.lua framework/cgi-bin/webmcp.lua framework/env/auth/openid/_curl.lua framework/env/encode/file_path.lua framework/env/execute/chunk.lua framework/env/locale/_get_translation_table.lua framework/env/net/send_mail.lua libraries/atom/atom.lua libraries/extos/extos.c libraries/luatex/luatex.lua libraries/mondelefant/example.lua libraries/mondelefant/mondelefant.lua libraries/mondelefant/mondelefant_atom_connector.lua libraries/mondelefant/mondelefant_native.c libraries/multirand/multirand.c libraries/nihil/nihil.lua libraries/rocketcgi/rocketcgi.lua
line diff
     1.1 --- a/framework/accelerator/webmcp_accelerator.c	Tue Apr 03 00:56:02 2012 +0200
     1.2 +++ b/framework/accelerator/webmcp_accelerator.c	Sun Apr 15 16:04:33 2012 +0200
     1.3 @@ -53,7 +53,11 @@
     1.4    lua_pushvalue(L, 1);
     1.5    lua_gettable(L, -2);  // get table by reference passed as 1st argument
     1.6    lua_getfield(L, -1, "string_fragments");
     1.7 +#ifdef LUA_VERSION_NUM >= 502
     1.8 +  j = lua_rawlen(L, -1);
     1.9 +#else
    1.10    j = lua_objlen(L, -1);
    1.11 +#endif
    1.12    for (i=2; i<=argc; i++) {
    1.13      lua_pushvalue(L, i);
    1.14      lua_rawseti(L, -2, ++j);
    1.15 @@ -71,7 +75,11 @@
    1.16    lua_getfield(L, -2, "_active_slot");
    1.17    lua_gettable(L, -2);
    1.18    lua_getfield(L, -1, "string_fragments");
    1.19 +#ifdef LUA_VERSION_NUM >= 502
    1.20 +  j = lua_rawlen(L, -1);
    1.21 +#else
    1.22    j = lua_objlen(L, -1);
    1.23 +#endif
    1.24    for (i=1; i<=argc; i++) {
    1.25      lua_pushvalue(L, i);
    1.26      lua_rawseti(L, -2, ++j);
    1.27 @@ -108,7 +116,11 @@
    1.28        tag_given = 1;
    1.29      }
    1.30    }
    1.31 +#ifdef LUA_VERSION_NUM >= 502
    1.32 +  j = lua_rawlen(L, 5);
    1.33 +#else
    1.34    j = lua_objlen(L, 5);
    1.35 +#endif
    1.36    if (tag_given) {
    1.37      lua_pushliteral(L, "<");
    1.38      lua_rawseti(L, 5, ++j);
    1.39 @@ -153,7 +165,11 @@
    1.40        lua_call(L, 0, 0);
    1.41        // stack is now at position 7, but we don't care
    1.42        // we assume that the active slot hasn't been exchanged or resetted
    1.43 +#ifdef LUA_VERSION_NUM >= 502
    1.44 +      j = lua_rawlen(L, 5);  // but it may include more elements now
    1.45 +#else
    1.46        j = lua_objlen(L, 5);  // but it may include more elements now
    1.47 +#endif
    1.48      } else {
    1.49        lua_pushcfunction(L, webmcp_encode_html);  // 9
    1.50        lua_pushvalue(L, 8);  // 10
     2.1 --- a/framework/bin/autodoc.lua	Tue Apr 03 00:56:02 2012 +0200
     2.2 +++ b/framework/bin/autodoc.lua	Sun Apr 15 16:04:33 2012 +0200
     2.3 @@ -213,4 +213,4 @@
     2.4    output('    </div>\n')
     2.5    output('  </div>\n')
     2.6    output('</li>\n')
     2.7 -end
     2.8 \ No newline at end of file
     2.9 +end
     3.1 --- a/framework/bin/langtool.lua	Tue Apr 03 00:56:02 2012 +0200
     3.2 +++ b/framework/bin/langtool.lua	Sun Apr 15 16:04:33 2012 +0200
     3.3 @@ -2,7 +2,7 @@
     3.4  
     3.5  if not pcall(
     3.6    function()
     3.7 -    require "extos"
     3.8 +    extos = require "extos"
     3.9    end
    3.10  ) then
    3.11    io.stderr:write('Could not load library "extos".\n')
    3.12 @@ -151,8 +151,13 @@
    3.13    end
    3.14  elseif in_filetype == "lua" then
    3.15    io.stderr:write('Reading translations from lua file "', in_filename, '".\n')
    3.16 -  local func = assert(loadfile(in_filename))
    3.17 -  setfenv(func, {})
    3.18 +  local func
    3.19 +  if _ENV then
    3.20 +    func = assert(loadfile(in_filename, "t", {}))
    3.21 +  else
    3.22 +    func = assert(loadfile(in_filename))
    3.23 +    setfenv(func, {})
    3.24 +  end
    3.25    local updates = func()
    3.26    for key, value in pairs(updates) do
    3.27      update_translation(key, value)
     4.1 --- a/framework/cgi-bin/webmcp.lua	Tue Apr 03 00:56:02 2012 +0200
     4.2 +++ b/framework/cgi-bin/webmcp.lua	Sun Apr 15 16:04:33 2012 +0200
     4.3 @@ -1,6 +1,11 @@
     4.4  #!/usr/bin/env lua
     4.5  
     4.6 -_WEBMCP_VERSION = "1.1.3"
     4.7 +_WEBMCP_VERSION = "1.1.4"
     4.8 +
     4.9 +-- Lua 5.1 compatibility
    4.10 +if not table.unpack then
    4.11 +  table.unpack = unpack
    4.12 +end
    4.13  
    4.14  -- include "../lib/" in search path for libraries
    4.15  if not WEBMCP_PATH then
    4.16 @@ -27,13 +32,13 @@
    4.17  
    4.18  -- load os extensions for lua
    4.19  -- (should happen as soon as possible due to run time measurement)
    4.20 -require 'extos'
    4.21 +extos = require 'extos'
    4.22  
    4.23  -- load nihil library
    4.24 -require 'nihil'
    4.25 +nihil = require 'nihil'
    4.26  
    4.27  -- load random generator library
    4.28 -require 'multirand'
    4.29 +multirand = require 'multirand'
    4.30  
    4.31  -- load rocketcgi library and map it to cgi
    4.32  do
    4.33 @@ -41,17 +46,17 @@
    4.34    if option and option ~= "" and option ~= "0" then
    4.35      cgi = nil
    4.36    else
    4.37 -    require 'rocketcgi'
    4.38 +    rocketcgi = require 'rocketcgi'
    4.39      cgi = rocketcgi
    4.40    end
    4.41  end
    4.42  
    4.43  -- load database access library with object relational mapper
    4.44 -require 'mondelefant'
    4.45 +mondelefant = require 'mondelefant'
    4.46  mondelefant.connection_prototype.error_objects = true
    4.47  
    4.48  -- load type system "atom"
    4.49 -require 'atom'
    4.50 +atom = require 'atom'
    4.51  
    4.52  -- load mondelefant atom connector
    4.53  require 'mondelefant_atom_connector'
     5.1 --- a/framework/env/auth/openid/_curl.lua	Tue Apr 03 00:56:02 2012 +0200
     5.2 +++ b/framework/env/auth/openid/_curl.lua	Sun Apr 15 16:04:33 2012 +0200
     5.3 @@ -6,7 +6,7 @@
     5.4    local options = table.new(curl_options)
     5.5    options[#options+1] = "-i"
     5.6    options[#options+1] = url
     5.7 -  local stdout, errmsg, status = os.pfilter(nil, "curl", unpack(options))
     5.8 +  local stdout, errmsg, status = os.pfilter(nil, "curl", table.unpack(options))
     5.9    if not stdout then
    5.10      error("Error while executing curl: " .. errmsg)
    5.11    end
     6.1 --- a/framework/env/encode/file_path.lua	Tue Apr 03 00:56:02 2012 +0200
     6.2 +++ b/framework/env/encode/file_path.lua	Sun Apr 15 16:04:33 2012 +0200
     6.3 @@ -17,5 +17,5 @@
     6.4    for i = 1, #raw_elements do
     6.5      encoded_elements[i] = encode.file_path_element(raw_elements[i])
     6.6    end
     6.7 -  return encode.concat_file_path(base, unpack(encoded_elements))
     6.8 +  return encode.concat_file_path(base, table.unpack(encoded_elements))
     6.9  end
     7.1 --- a/framework/env/execute/chunk.lua	Tue Apr 03 00:56:02 2012 +0200
     7.2 +++ b/framework/env/execute/chunk.lua	Sun Apr 15 16:04:33 2012 +0200
     7.3 @@ -44,5 +44,5 @@
     7.4      param.restore()
     7.5    end
     7.6  
     7.7 -  return unpack(result)
     7.8 +  return table.unpack(result)
     7.9  end
     8.1 --- a/framework/env/locale/_get_translation_table.lua	Tue Apr 03 00:56:02 2012 +0200
     8.2 +++ b/framework/env/locale/_get_translation_table.lua	Sun Apr 15 16:04:33 2012 +0200
     8.3 @@ -9,8 +9,13 @@
     8.4        return translation_table
     8.5      end
     8.6      local filename = encode.file_path(request.get_app_basepath(), "locale", "translations." .. language_code .. ".lua")
     8.7 -    local func = assert(loadfile(filename))
     8.8 -    setfenv(func, {})
     8.9 +    local func
    8.10 +    if _ENV then
    8.11 +      func = assert(loadfile(filename), nil, {})
    8.12 +    else
    8.13 +      func = assert(loadfile(filename))
    8.14 +      setfenv(func, {})
    8.15 +    end
    8.16      translation_table = func()
    8.17      if type(translation_table) ~= "table" then
    8.18        error("Translation file did not return a table.")
     9.1 --- a/framework/env/net/send_mail.lua	Tue Apr 03 00:56:02 2012 +0200
     9.2 +++ b/framework/env/net/send_mail.lua	Sun Apr 15 16:04:33 2012 +0200
     9.3 @@ -46,7 +46,7 @@
     9.4      command[#command+1] = "-f"
     9.5      command[#command+1] = envelope_from
     9.6    end
     9.7 -  local stdout, errmsg, status = os.pfilter(mail, unpack(command))
     9.8 +  local stdout, errmsg, status = os.pfilter(mail, table.unpack(command))
     9.9    if not status then
    9.10      error("Error while calling sendmail: " .. errmsg)
    9.11    end
    10.1 --- a/libraries/atom/atom.lua	Tue Apr 03 00:56:02 2012 +0200
    10.2 +++ b/libraries/atom/atom.lua	Sun Apr 15 16:04:33 2012 +0200
    10.3 @@ -4,33 +4,32 @@
    10.4  local _VERSION       = _VERSION
    10.5  local assert         = assert
    10.6  local error          = error
    10.7 -local getfenv        = getfenv
    10.8  local getmetatable   = getmetatable
    10.9  local ipairs         = ipairs
   10.10 -local module         = module
   10.11  local next           = next
   10.12  local pairs          = pairs
   10.13  local print          = print
   10.14  local rawequal       = rawequal
   10.15  local rawget         = rawget
   10.16 +local rawlen         = rawlen
   10.17  local rawset         = rawset
   10.18 -local require        = require
   10.19  local select         = select
   10.20 -local setfenv        = setfenv
   10.21  local setmetatable   = setmetatable
   10.22  local tonumber       = tonumber
   10.23  local tostring       = tostring
   10.24  local type           = type
   10.25 -local unpack         = unpack
   10.26  
   10.27 -local coroutine = coroutine
   10.28 -local io        = io
   10.29  local math      = math
   10.30 -local os        = os
   10.31  local string    = string
   10.32  local table     = table
   10.33  
   10.34 -module(...)
   10.35 +local _M = {}
   10.36 +if _ENV then
   10.37 +  _ENV = _M
   10.38 +else
   10.39 +  _G[...] = _M
   10.40 +  setfenv(1, _M)
   10.41 +end
   10.42  
   10.43  
   10.44  
   10.45 @@ -1537,3 +1536,6 @@
   10.46    end
   10.47  end
   10.48  
   10.49 +
   10.50 +
   10.51 +return _M
    11.1 --- a/libraries/extos/extos.c	Tue Apr 03 00:56:02 2012 +0200
    11.2 +++ b/libraries/extos/extos.c	Sun Apr 15 16:04:33 2012 +0200
    11.3 @@ -328,6 +328,15 @@
    11.4    return 1;
    11.5  }
    11.6  
    11.7 +static const struct luaL_Reg extos_module_functions[] = {
    11.8 +  {"pfilter",              extos_pfilter},
    11.9 +  {"listdir",              extos_listdir},
   11.10 +  {"crypt",                extos_crypt},
   11.11 +  {"hires_time",           extos_hires_time},
   11.12 +  {"monotonic_hires_time", extos_monotonic_hires_time},
   11.13 +  {NULL, NULL}
   11.14 +};
   11.15 +
   11.16  int luaopen_extos(lua_State *L) {
   11.17    {
   11.18      struct timespec tp;
   11.19 @@ -336,16 +345,11 @@
   11.20      }
   11.21      extos_monotonic_start_time = tp.tv_sec + 0.000000001 * tp.tv_nsec;
   11.22    }
   11.23 -  lua_getglobal(L, "os");
   11.24 -  lua_pushcfunction(L, extos_pfilter);
   11.25 -  lua_setfield(L, -2, "pfilter");
   11.26 -  lua_pushcfunction(L, extos_listdir);
   11.27 -  lua_setfield(L, -2, "listdir");
   11.28 -  lua_pushcfunction(L, extos_crypt);
   11.29 -  lua_setfield(L, -2, "crypt");
   11.30 -  lua_pushcfunction(L, extos_hires_time);
   11.31 -  lua_setfield(L, -2, "hires_time");
   11.32 -  lua_pushcfunction(L, extos_monotonic_hires_time);
   11.33 -  lua_setfield(L, -2, "monotonic_hires_time");
   11.34 -  return 0;
   11.35 +#if LUA_VERSION_NUM >= 502
   11.36 +  lua_newtable(L);
   11.37 +  luaL_setfuncs(L, extos_module_functions, 0);
   11.38 +#else
   11.39 +  luaL_register(L, lua_tostring(L, 1) || "extos", extos_module_functions);
   11.40 +#endif
   11.41 +  return 1;
   11.42  }
    12.1 --- a/libraries/luatex/luatex.lua	Tue Apr 03 00:56:02 2012 +0200
    12.2 +++ b/libraries/luatex/luatex.lua	Sun Apr 15 16:04:33 2012 +0200
    12.3 @@ -3,48 +3,42 @@
    12.4  local _G             = _G
    12.5  local _VERSION       = _VERSION
    12.6  local assert         = assert
    12.7 -local collectgarbage = collectgarbage
    12.8 -local dofile         = dofile
    12.9  local error          = error
   12.10 -local getfenv        = getfenv
   12.11  local getmetatable   = getmetatable
   12.12  local ipairs         = ipairs
   12.13 -local load           = load
   12.14 -local loadfile       = loadfile
   12.15 -local loadstring     = loadstring
   12.16 -local module         = module
   12.17  local next           = next
   12.18  local pairs          = pairs
   12.19 -local pcall          = pcall
   12.20  local print          = print
   12.21  local rawequal       = rawequal
   12.22  local rawget         = rawget
   12.23 +local rawlen         = rawlen
   12.24  local rawset         = rawset
   12.25 -local require        = require
   12.26  local select         = select
   12.27 -local setfenv        = setfenv
   12.28  local setmetatable   = setmetatable
   12.29  local tonumber       = tonumber
   12.30  local tostring       = tostring
   12.31  local type           = type
   12.32 -local unpack         = unpack
   12.33 -local xpcall         = xpcall
   12.34  
   12.35 -local coroutine = coroutine
   12.36 -local debug     = debug
   12.37  local io        = io
   12.38  local math      = math
   12.39  local os        = os
   12.40 -local package   = package
   12.41  local string    = string
   12.42  local table     = table
   12.43  
   12.44 -require("multirand")
   12.45 -local multirand = multirand
   12.46 +local multirand = require("multirand")
   12.47  
   12.48 -module(...)
   12.49 +local _M = {}
   12.50 +if _ENV then
   12.51 +  _ENV = _M
   12.52 +else
   12.53 +  _G[...] = _M
   12.54 +  setfenv(1, _M)
   12.55 +end
   12.56  
   12.57 -temp_dir = false  -- has to be set to a private directory (/tmp can be unsafe)
   12.58 +-- NOTE:
   12.59 +-- temp_dir MUST NOT contain any charactes interpreted by system shell
   12.60 +-- and has to be set to a private directory (/tmp may be unsafe)
   12.61 +temp_dir = false
   12.62  
   12.63  function escape(str)
   12.64    return (
   12.65 @@ -101,7 +95,8 @@
   12.66  end
   12.67  
   12.68  function document_methods:get_pdf()
   12.69 -  -- TODO: proper escaping of shell commands (should not be a real risk)
   12.70 +  -- TODO: proper escaping of shell commands
   12.71 +  -- (not a security risk, as args are safe)
   12.72    if not temp_dir then
   12.73      error("luatex.temp_dir not set")
   12.74    end
   12.75 @@ -109,11 +104,12 @@
   12.76    local latex_file = assert(io.open(basename .. ".tex", "w"))
   12.77    latex_file:write(self:get_latex())
   12.78    latex_file:close()
   12.79 -  local result = os.execute(
   12.80 +  local result1, result2, result3 = os.execute(
   12.81      'latex -output-format=pdf "-output-directory=' .. temp_dir .. '" ' ..
   12.82      basename .. '< /dev/null > /dev/null 2> /dev/null'
   12.83    )
   12.84 -  if result ~= 0 then
   12.85 +  -- NOTE: use result1 and result3 for lua5.1 and lua5.2 compatibility
   12.86 +  if not (result1 == 0 or (result2 == "exit" and result3 == 0)) then
   12.87      error('LaTeX failed, see "' .. basename .. '.log" for details.')
   12.88    end
   12.89    local pdf_file = assert(io.open(basename .. ".pdf", "r"))
   12.90 @@ -123,9 +119,11 @@
   12.91    return pdf_data
   12.92  end
   12.93  
   12.94 +return _M
   12.95 +
   12.96  --[[
   12.97  
   12.98 -require("luatex")
   12.99 +luatex = require("luatex")
  12.100  luatex.temp_dir = "."
  12.101  
  12.102  local tex = luatex.new_document()
    13.1 --- a/libraries/mondelefant/example.lua	Tue Apr 03 00:56:02 2012 +0200
    13.2 +++ b/libraries/mondelefant/example.lua	Sun Apr 15 16:04:33 2012 +0200
    13.3 @@ -1,5 +1,5 @@
    13.4  #!/usr/bin/env lua
    13.5 -require("mondelefant")
    13.6 +mondelefant = require("mondelefant")
    13.7  
    13.8  -- Standarddatenbankverbindung ist globale Variable 'db'
    13.9  function mondelefant.class_prototype:get_db_conn() return db end
   13.10 @@ -83,4 +83,4 @@
   13.11  sel:add_field("*")
   13.12  sel:attach("m1", products, "product_id", "id", "product", "product_variants")
   13.13  product_variants = sel:exec()
   13.14 ---]]
   13.15 \ No newline at end of file
   13.16 +--]]
    14.1 --- a/libraries/mondelefant/mondelefant.lua	Tue Apr 03 00:56:02 2012 +0200
    14.2 +++ b/libraries/mondelefant/mondelefant.lua	Sun Apr 15 16:04:33 2012 +0200
    14.3 @@ -8,42 +8,35 @@
    14.4  local _G              = _G
    14.5  local _VERSION        = _VERSION
    14.6  local assert          = assert
    14.7 -local collectgarbage  = collectgarbage
    14.8 -local dofile          = dofile
    14.9  local error           = error
   14.10 -local getfenv         = getfenv
   14.11  local getmetatable    = getmetatable
   14.12  local ipairs          = ipairs
   14.13 -local load            = load
   14.14 -local loadfile        = loadfile
   14.15 -local loadstring      = loadstring
   14.16  local next            = next
   14.17  local pairs           = pairs
   14.18 -local pcall           = pcall
   14.19  local print           = print
   14.20  local rawequal        = rawequal
   14.21  local rawget          = rawget
   14.22 +local rawlen          = rawlen
   14.23  local rawset          = rawset
   14.24  local select          = select
   14.25 -local setfenv         = setfenv
   14.26  local setmetatable    = setmetatable
   14.27  local tonumber        = tonumber
   14.28  local tostring        = tostring
   14.29  local type            = type
   14.30 -local unpack          = unpack
   14.31 -local xpcall          = xpcall
   14.32  
   14.33 -local coroutine       = coroutine
   14.34 -local io              = io
   14.35  local math            = math
   14.36 -local os              = os
   14.37  local string          = string
   14.38  local table           = table
   14.39  
   14.40  local add             = table.insert
   14.41  
   14.42 -_G[...] = require("mondelefant_native")
   14.43 -module(...)
   14.44 +local _M = require("mondelefant_native")
   14.45 +if _ENV then
   14.46 +  _ENV = _M
   14.47 +else
   14.48 +  _G[...] = _M
   14.49 +  setfenv(1, _M)
   14.50 +end
   14.51  
   14.52  
   14.53  
    15.1 --- a/libraries/mondelefant/mondelefant_atom_connector.lua	Tue Apr 03 00:56:02 2012 +0200
    15.2 +++ b/libraries/mondelefant/mondelefant_atom_connector.lua	Sun Apr 15 16:04:33 2012 +0200
    15.3 @@ -3,45 +3,36 @@
    15.4  local _G             = _G
    15.5  local _VERSION       = _VERSION
    15.6  local assert         = assert
    15.7 -local collectgarbage = collectgarbage
    15.8 -local dofile         = dofile
    15.9  local error          = error
   15.10 -local getfenv        = getfenv
   15.11  local getmetatable   = getmetatable
   15.12  local ipairs         = ipairs
   15.13 -local load           = load
   15.14 -local loadfile       = loadfile
   15.15 -local loadstring     = loadstring
   15.16 -local module         = module
   15.17  local next           = next
   15.18  local pairs          = pairs
   15.19 -local pcall          = pcall
   15.20  local print          = print
   15.21  local rawequal       = rawequal
   15.22  local rawget         = rawget
   15.23 +local rawlen         = rawlen
   15.24  local rawset         = rawset
   15.25 -local require        = require
   15.26  local select         = select
   15.27 -local setfenv        = setfenv
   15.28  local setmetatable   = setmetatable
   15.29  local tonumber       = tonumber
   15.30  local tostring       = tostring
   15.31  local type           = type
   15.32 -local unpack         = unpack
   15.33 -local xpcall         = xpcall
   15.34  
   15.35 -local coroutine = coroutine
   15.36 -local debug     = debug
   15.37 -local io        = io
   15.38  local math      = math
   15.39 -local os        = os
   15.40 -local package   = package
   15.41  local string    = string
   15.42 +local table     = table
   15.43  
   15.44  local mondelefant = require("mondelefant")
   15.45  local atom        = require("atom")
   15.46  
   15.47 -module(...)
   15.48 +local _M = {}
   15.49 +if _ENV then
   15.50 +  _ENV = _M
   15.51 +else
   15.52 +  _G[...] = _M
   15.53 +  setfenv(1, _M)
   15.54 +end
   15.55  
   15.56  
   15.57  input_converters = setmetatable({}, { __mode = "k" })
   15.58 @@ -179,6 +170,8 @@
   15.59    end
   15.60  end
   15.61  
   15.62 +return _M
   15.63 +
   15.64  
   15.65  --[[
   15.66  
    16.1 --- a/libraries/mondelefant/mondelefant_native.c	Tue Apr 03 00:56:02 2012 +0200
    16.2 +++ b/libraries/mondelefant/mondelefant_native.c	Sun Apr 15 16:04:33 2012 +0200
    16.3 @@ -632,7 +632,11 @@
    16.4          }
    16.5          luaL_pushresult(&keybuf);
    16.6          // check, if any characters matched:
    16.7 +#if LUA_VERSION_NUM >= 502
    16.8 +        if (lua_rawlen(L, -1)) {
    16.9 +#else
   16.10          if (lua_objlen(L, -1)) {
   16.11 +#endif
   16.12            // if any alpha numeric chars or underscores were found,
   16.13            // push them on stack as a Lua string and use them to lookup
   16.14            // value from second argument:
   16.15 @@ -683,7 +687,11 @@
   16.16              );
   16.17            }
   16.18            // iterate over items of sub-structure:
   16.19 +#if LUA_VERSION_NUM >= 502
   16.20 +          count = lua_rawlen(L, 5);
   16.21 +#else
   16.22            count = lua_objlen(L, 5);
   16.23 +#endif
   16.24            for (i = 0; i < count; i++) {
   16.25              // add seperator, unless this is the first run:
   16.26              if (i) {
   16.27 @@ -1137,9 +1145,17 @@
   16.28      lua_rawgeti(L, 3, command_idx+1);  // raw result at stack position 5
   16.29      if (lua_toboolean(L, 5)) {
   16.30        lua_getfield(L, 5, "_column_info");  // column_info list at position 6
   16.31 +#if LUA_VERSION_NUM >= 502
   16.32 +      cols = lua_rawlen(L, 6);
   16.33 +#else
   16.34        cols = lua_objlen(L, 6);
   16.35 +#endif
   16.36        if (mode == MONDELEFANT_QUERY_MODE_LIST) {
   16.37 +#if LUA_VERSION_NUM >= 502
   16.38 +        rows = lua_rawlen(L, 5);
   16.39 +#else
   16.40          rows = lua_objlen(L, 5);
   16.41 +#endif
   16.42          for (row = 0; row < rows; row++) {
   16.43            lua_rawgeti(L, 5, row+1);  // row at stack position 7
   16.44            lua_getfield(L, 7, "_data");  // _data table at stack position 8
   16.45 @@ -1260,12 +1276,20 @@
   16.46    lua_settop(L, 2);
   16.47    lua_getmetatable(L, 1);  // 3
   16.48    lua_getfield(L, LUA_REGISTRYINDEX, MONDELEFANT_RESULT_MT_REGKEY);  // 4
   16.49 +#if LUA_VERSION_NUM >= 502
   16.50 +  luaL_argcheck(L, lua_compare(L, 3, 4, LUA_OPEQ), 1, "not a database result");
   16.51 +#else
   16.52    luaL_argcheck(L, lua_equal(L, 3, 4), 1, "not a database result");
   16.53 +#endif
   16.54    // ensure that second argument is a database class (model):
   16.55    lua_settop(L, 2);
   16.56    lua_getmetatable(L, 2);  // 3
   16.57    lua_getfield(L, LUA_REGISTRYINDEX, MONDELEFANT_CLASS_MT_REGKEY);  // 4
   16.58 +#if LUA_VERSION_NUM >= 502
   16.59 +  luaL_argcheck(L, lua_compare(L, 3, 4, LUA_OPEQ), 2, "not a database class");
   16.60 +#else
   16.61    luaL_argcheck(L, lua_equal(L, 3, 4), 2, "not a database class");
   16.62 +#endif
   16.63    // set attribute "_class" of result list/object to given class:
   16.64    lua_settop(L, 2);
   16.65    lua_pushvalue(L, 2);  // 3
   16.66 @@ -1276,7 +1300,11 @@
   16.67    if (lua_rawequal(L, 3, 4)) {
   16.68      int i;
   16.69      // set attribute "_class" of all elements to given class:
   16.70 +#if LUA_VERSION_NUM >= 502
   16.71 +    for (i=0; i < lua_rawlen(L, 1); i++) {
   16.72 +#else
   16.73      for (i=0; i < lua_objlen(L, 1); i++) {
   16.74 +#endif
   16.75        lua_settop(L, 2);
   16.76        lua_rawgeti(L, 1, i+1);  // 3
   16.77        lua_pushvalue(L, 2);  // 4
   16.78 @@ -1740,38 +1768,66 @@
   16.79  int luaopen_mondelefant_native(lua_State *L) {
   16.80    lua_settop(L, 0);
   16.81    lua_newtable(L);  // module at stack position 1
   16.82 +#if LUA_VERSION_NUM >= 502
   16.83 +  luaL_setfuncs(L, mondelefant_module_functions, 0);
   16.84 +#else
   16.85    luaL_register(L, NULL, mondelefant_module_functions);
   16.86 +#endif
   16.87  
   16.88    lua_pushvalue(L, 1);  // 2
   16.89    lua_setfield(L, LUA_REGISTRYINDEX, MONDELEFANT_MODULE_REGKEY);
   16.90  
   16.91    lua_newtable(L);  // 2
   16.92    // NOTE: only PostgreSQL is supported yet:
   16.93 +#if LUA_VERSION_NUM >= 502
   16.94 +  luaL_setfuncs(L, mondelefant_conn_methods, 0);
   16.95 +#else
   16.96    luaL_register(L, NULL, mondelefant_conn_methods);
   16.97 +#endif
   16.98    lua_setfield(L, 1, "postgresql_connection_prototype");
   16.99    lua_newtable(L);  // 2
  16.100    lua_setfield(L, 1, "connection_prototype");
  16.101  
  16.102    luaL_newmetatable(L, MONDELEFANT_CONN_MT_REGKEY);  // 2
  16.103 +#if LUA_VERSION_NUM >= 502
  16.104 +  luaL_setfuncs(L, mondelefant_conn_mt_functions, 0);
  16.105 +#else
  16.106    luaL_register(L, NULL, mondelefant_conn_mt_functions);
  16.107 +#endif
  16.108    lua_settop(L, 1);
  16.109    luaL_newmetatable(L, MONDELEFANT_RESULT_MT_REGKEY);  // 2
  16.110 +#if LUA_VERSION_NUM >= 502
  16.111 +  luaL_setfuncs(L, mondelefant_result_mt_functions, 0);
  16.112 +#else
  16.113    luaL_register(L, NULL, mondelefant_result_mt_functions);
  16.114 +#endif
  16.115    lua_setfield(L, 1, "result_metatable");
  16.116    luaL_newmetatable(L, MONDELEFANT_CLASS_MT_REGKEY);  // 2
  16.117 +#if LUA_VERSION_NUM >= 502
  16.118 +  luaL_setfuncs(L, mondelefant_class_mt_functions, 0);
  16.119 +#else
  16.120    luaL_register(L, NULL, mondelefant_class_mt_functions);
  16.121 +#endif
  16.122    lua_setfield(L, 1, "class_metatable");
  16.123  
  16.124    lua_newtable(L);  // 2
  16.125    lua_newtable(L);  // 3
  16.126 +#if LUA_VERSION_NUM >= 502
  16.127 +  luaL_setfuncs(L, mondelefant_object_methods, 0);
  16.128 +#else
  16.129    luaL_register(L, NULL, mondelefant_object_methods);
  16.130 +#endif
  16.131    lua_setfield(L, 2, "object");
  16.132    lua_newtable(L);  // 3
  16.133    lua_setfield(L, 2, "object_get");
  16.134    lua_newtable(L);  // 3
  16.135    lua_setfield(L, 2, "object_set");
  16.136    lua_newtable(L);  // 3
  16.137 +#if LUA_VERSION_NUM >= 502
  16.138 +  luaL_setfuncs(L, mondelefant_list_methods, 0);
  16.139 +#else
  16.140    luaL_register(L, NULL, mondelefant_list_methods);
  16.141 +#endif
  16.142    lua_setfield(L, 2, "list");
  16.143    lua_newtable(L);  // 3
  16.144    lua_setfield(L, 2, "references");
  16.145 @@ -1791,9 +1847,17 @@
  16.146    lua_settop(L, 1);
  16.147  
  16.148    luaL_newmetatable(L, MONDELEFANT_ERROROBJECT_MT_REGKEY);  // 2
  16.149 +#if LUA_VERSION_NUM >= 502
  16.150 +  luaL_setfuncs(L, mondelefant_errorobject_mt_functions, 0);
  16.151 +#else
  16.152    luaL_register(L, NULL, mondelefant_errorobject_mt_functions);
  16.153 +#endif
  16.154    lua_newtable(L);  // 3
  16.155 +#if LUA_VERSION_NUM >= 502
  16.156 +  luaL_setfuncs(L, mondelefant_errorobject_methods, 0);
  16.157 +#else
  16.158    luaL_register(L, NULL, mondelefant_errorobject_methods);
  16.159 +#endif
  16.160    lua_setfield(L, 2, "__index");
  16.161    lua_setfield(L, 1, "errorobject_metatable");
  16.162  
    17.1 --- a/libraries/multirand/multirand.c	Tue Apr 03 00:56:02 2012 +0200
    17.2 +++ b/libraries/multirand/multirand.c	Sun Apr 15 16:04:33 2012 +0200
    17.3 @@ -1,6 +1,5 @@
    17.4  #include <lua.h>
    17.5  #include <lauxlib.h>
    17.6 -#include <dirent.h>
    17.7  
    17.8  static FILE *multirand_dev;
    17.9  
   17.10 @@ -43,7 +42,7 @@
   17.11    lua_settop(L, 2);
   17.12    arg1 = luaL_checkinteger(L, 1);
   17.13    if (lua_toboolean(L, 2)) {
   17.14 -    arg2 = luaL_optinteger(L, 2, 0);
   17.15 +    arg2 = luaL_checkinteger(L, 2);
   17.16      if (arg1 > arg2) {
   17.17        return luaL_error(L,
   17.18          "Upper boundary is smaller than lower boundary."
   17.19 @@ -109,16 +108,13 @@
   17.20  };
   17.21  
   17.22  int luaopen_multirand(lua_State *L) {
   17.23 -  const char *module_name;
   17.24 -  lua_settop(L, 1);
   17.25 -  module_name = lua_tostring(L, 1);
   17.26 -  if (module_name) {
   17.27 -    luaL_register(L, module_name, multirand_module_functions);
   17.28 -  } else {
   17.29 -    luaL_register(L, "multirand", multirand_module_functions);
   17.30 -  }
   17.31 -  lua_replace(L, 1);
   17.32    multirand_dev = fopen("/dev/urandom", "r");
   17.33    if (!multirand_dev) return luaL_error(L, "Could not open /dev/urandom.");
   17.34 +#if LUA_VERSION_NUM >= 502
   17.35 +  lua_newtable(L);
   17.36 +  luaL_setfuncs(L, multirand_module_functions, 0);
   17.37 +#else
   17.38 +  luaL_register(L, lua_tostring(L, 1) || "multirand", multirand_module_functions);
   17.39 +#endif
   17.40    return 1;
   17.41  }
    18.1 --- a/libraries/nihil/nihil.lua	Tue Apr 03 00:56:02 2012 +0200
    18.2 +++ b/libraries/nihil/nihil.lua	Sun Apr 15 16:04:33 2012 +0200
    18.3 @@ -2,11 +2,16 @@
    18.4  
    18.5  local error          = error
    18.6  local getmetatable   = getmetatable
    18.7 -local module         = module
    18.8  local rawset         = rawset
    18.9  local setmetatable   = setmetatable
   18.10  
   18.11 -module(...)
   18.12 +local _M = {}
   18.13 +if _ENV then
   18.14 +  _ENV = _M
   18.15 +else
   18.16 +  _G[...] = _M
   18.17 +  setfenv(1, _M)
   18.18 +end
   18.19  
   18.20  metatable = {
   18.21    __tostring = function(self)
   18.22 @@ -50,3 +55,5 @@
   18.23      return value
   18.24    end
   18.25  end
   18.26 +
   18.27 +return _M
    19.1 --- a/libraries/rocketcgi/rocketcgi.lua	Tue Apr 03 00:56:02 2012 +0200
    19.2 +++ b/libraries/rocketcgi/rocketcgi.lua	Sun Apr 15 16:04:33 2012 +0200
    19.3 @@ -3,24 +3,20 @@
    19.4  local assert         = assert
    19.5  local collectgarbage = collectgarbage
    19.6  local error          = error
    19.7 -local getfenv        = getfenv
    19.8  local getmetatable   = getmetatable
    19.9  local ipairs         = ipairs
   19.10  local next           = next
   19.11  local pairs          = pairs
   19.12 -local pcall          = pcall
   19.13  local print          = print
   19.14  local rawequal       = rawequal
   19.15  local rawget         = rawget
   19.16 +local rawlen         = rawlen
   19.17  local rawset         = rawset
   19.18  local select         = select
   19.19 -local setfenv        = setfenv
   19.20  local setmetatable   = setmetatable
   19.21  local tonumber       = tonumber
   19.22  local tostring       = tostring
   19.23  local type           = type
   19.24 -local unpack         = unpack
   19.25 -local xpcall         = xpcall
   19.26  
   19.27  local io     = io
   19.28  local math   = math
   19.29 @@ -28,7 +24,13 @@
   19.30  local string = string
   19.31  local table  = table
   19.32  
   19.33 -module(...)
   19.34 +local _M = {}
   19.35 +if _ENV then
   19.36 +  _ENV = _M
   19.37 +else
   19.38 +  _G[...] = _M
   19.39 +  setfenv(1, _M)
   19.40 +end
   19.41  
   19.42  data_sent = false
   19.43  
   19.44 @@ -307,3 +309,5 @@
   19.45  else
   19.46    post_data = nil
   19.47  end
   19.48 +
   19.49 +return _M

Impressum / About Us