Permalink
Browse files

Make apr.version_get() return a table of versions

  • Loading branch information...
1 parent 2fd7736 commit b4030235ddecd44b6ddc3d9812b1597b51027e4d @xolox committed Jul 1, 2011
Showing with 44 additions and 24 deletions.
  1. +1 −1 src/apr.lua
  2. +35 −16 src/lua_apr.c
  3. +5 −4 test/misc.lua
  4. +3 −3 test/thread-child.lua
View
@@ -14,7 +14,7 @@
--]]
local apr = require 'apr.core'
-apr._VERSION = '0.19.6'
+apr._VERSION = '0.19.7'
-- apr.md5(input [, binary]) -> digest {{{1
--
View
@@ -9,6 +9,9 @@
#include "lua_apr.h"
#include <apr_portable.h>
#include <ctype.h>
+#if LUA_APR_HAVE_APREQ
+#include <apreq_version.h>
+#endif
/* Used to make sure that APR is only initialized once. */
static int apr_was_initialized = 0;
@@ -268,22 +271,33 @@ int lua_apr_platform_get(lua_State *L)
return 1;
}
-/* apr.version_get() -> apr_version [, apu_version] {{{1
+/* apr.version_get() -> versions_table {{{1
*
- * Get the version number of the Apache Portable Runtime as a string. The
- * string contains three numbers separated by dots. These numbers have the
- * following meaning:
+ * Get the versions of the libraries used by the Lua/APR binding.
+ * Returns a table with one or more of the following fields:
*
- * - The 1st number is used for major [API] [api] changes that can cause
- * compatibility problems between the Lua/APR binding and APR library
- * - The 2nd number is used for minor API changes that shouldn't impact
- * existing functionality in the Lua/APR binding
- * - The 3rd number is used exclusively for bug fixes
+ * - **apr**: The version of the Apache Portable Runtime library. This field
+ * is always available.
*
- * The second return value, the version number of the APR utility library, is
- * only available when Lua/APR is compiled against APR 1.x because in APR 2.x
- * the utility library has been absorbed back into the APR library; there is no
- * longer a distinction between the APR core and APR utility libraries.
+ * - **aprutil**: The version of the APR utility library. This field is only
+ * available when Lua/APR is compiled against APR and APR-util 1.x because
+ * in version 2.x the utility library has been absorbed back into the APR
+ * library; there is no longer a distinction between the APR core and APR
+ * utility libraries.
+ *
+ * - **apreq**: The version of the HTTP request parsing library. This field is
+ * only available when the libapreq2 library is installed.
+ *
+ * Each field is a string containing three numbers separated by dots. These
+ * numbers have the following meaning:
+ *
+ * 1. Major [API] [api] changes that can cause compatibility problems between
+ * the Lua/APR binding and APR library
+ *
+ * 2. Minor API changes that shouldn't impact existing functionality in the
+ * Lua/APR binding
+ *
+ * 3. Used exclusively for bug fixes
*
* This function can be useful when you want to know whether a certain bug fix
* has been applied to APR and/or APR-util or if you want to report a bug in
@@ -298,13 +312,18 @@ int lua_apr_platform_get(lua_State *L)
int lua_apr_version_get(lua_State *L)
{
+ lua_newtable(L);
lua_pushstring(L, apr_version_string());
+ lua_setfield(L, -2, "apr");
# if APR_MAJOR_VERSION < 2
lua_pushstring(L, apu_version_string());
- return 2;
-# else
- return 1;
+ lua_setfield(L, -2, "aprutil");
# endif
+# if LUA_APR_HAVE_APREQ
+ lua_pushstring(L, apreq_version_string());
+ lua_setfield(L, -2, "apreq");
+# endif
+ return 1;
}
/* apr.os_default_encoding() -> name {{{1
View
@@ -3,7 +3,7 @@
Unit tests for the miscellaneous routines of the Lua/APR binding.
Author: Peter Odding <peter@peterodding.com>
- Last Change: March 27, 2011
+ Last Change: July 1, 2011
Homepage: http://peterodding.com/code/lua/apr/
License: MIT
@@ -24,9 +24,10 @@ assert(apr.type(apr.proc_create 'test') == 'process')
assert(apr.type(apr.dir_open '.') == 'directory')
-- Test apr.version_get()
-local apr_v, apu_v = assert(apr.version_get())
-assert(apr_v:find '^%d+%.%d+%.%d+$')
-assert(apu_v:find '^%d+%.%d+%.%d+$')
+local v = apr.version_get()
+assert(v.apr:find '^%d+%.%d+%.%d+$')
+assert(v.aprutil == nil or v.aprutil:find '^%d+%.%d+%.%d+$')
+assert(v.apreq == nil or v.apreq:find '^%d+%.%d+%.%d+$')
-- Test status_to_name() (indirectly).
assert(select(3, apr.stat("I assume this won't exist")) == 'ENOENT')
View
@@ -3,7 +3,7 @@
Unit tests for the multi threading module of the Lua/APR binding.
Author: Peter Odding <peter@peterodding.com>
- Last Change: June 21, 2011
+ Last Change: July 1, 2011
Homepage: http://peterodding.com/code/lua/apr/
License: MIT
@@ -40,9 +40,9 @@ local thread = apr.thread(function()
pcall(require, 'luarocks.require')
apr = require 'apr'
end
- return apr.version_get()
+ return apr.version_get().apr
end)
-helpers.checktuple({ true, apr.version_get() }, assert(thread:join()))
+helpers.checktuple({ true, apr.version_get().apr }, assert(thread:join()))
-- Test thread:status()
local thread = apr.thread(function()

0 comments on commit b403023

Please sign in to comment.