# HG changeset patch
# User Sebastien Jodogne <s.jodogne@gmail.com>
# Date 1367247571 -7200
# Node ID 18fe778eeb954b17a91cced64f3b5482f60920ca
# Parent  b45bc565d82a571864095f1be34b773e7efc505e
wrapper around lua

diff -r b45bc565d82a -r 18fe778eeb95 CMakeLists.txt
--- a/CMakeLists.txt	Mon Apr 29 13:31:10 2013 +0200
+++ b/CMakeLists.txt	Mon Apr 29 16:59:31 2013 +0200
@@ -79,6 +79,7 @@
 set(EMBEDDED_FILES
   PREPARE_DATABASE ${CMAKE_CURRENT_SOURCE_DIR}/OrthancServer/PrepareDatabase.sql
   CONFIGURATION_SAMPLE ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Configuration.json
+  LUA_TOOLBOX ${CMAKE_CURRENT_SOURCE_DIR}/Resources/Toolbox.lua
   )
 
 if (${STANDALONE_BUILD})
@@ -201,6 +202,7 @@
       UnitTests/ServerIndex.cpp
       UnitTests/Versions.cpp
       UnitTests/Zip.cpp
+      UnitTests/Lua.cpp
       UnitTests/main.cpp
       )
     target_link_libraries(UnitTests ServerLibrary CoreLibrary)
diff -r b45bc565d82a -r 18fe778eeb95 Core/OrthancException.h
--- a/Core/OrthancException.h	Mon Apr 29 13:31:10 2013 +0200
+++ b/Core/OrthancException.h	Mon Apr 29 16:59:31 2013 +0200
@@ -39,13 +39,19 @@
 {
   class OrthancException
   {
-  private:
+  protected:
     ErrorCode error_;
     std::string custom_;
 
   public:
     static const char* GetDescription(ErrorCode error);
 
+    OrthancException(const char* custom)
+    {
+      error_ = ErrorCode_Custom;
+      custom_ = custom;
+    }
+
     OrthancException(const std::string& custom)
     {
       error_ = ErrorCode_Custom;
diff -r b45bc565d82a -r 18fe778eeb95 Resources/CMake/LuaConfiguration.cmake
--- a/Resources/CMake/LuaConfiguration.cmake	Mon Apr 29 13:31:10 2013 +0200
+++ b/Resources/CMake/LuaConfiguration.cmake	Mon Apr 29 16:59:31 2013 +0200
@@ -3,7 +3,9 @@
   DownloadPackage("http://www.montefiore.ulg.ac.be/~jodogne/Orthanc/ThirdPartyDownloads/lua-5.1.5.tar.gz" "${LUA_SOURCES_DIR}" "" "")
 
   add_definitions(
-    -DLUA_COMPAT_ALL=1  # Compile a generic version of Lua
+    #-DLUA_LIB=1
+    #-Dluaall_c=1
+    #-DLUA_COMPAT_ALL=1  # Compile a generic version of Lua
     )
 
   include_directories(
@@ -32,8 +34,17 @@
     ${LUA_SOURCES_DIR}/src/lvm.c 
     ${LUA_SOURCES_DIR}/src/lzio.c
 
-    # Additional modules
+    # Base Lua modules
+    ${LUA_SOURCES_DIR}/src/lauxlib.c
+    ${LUA_SOURCES_DIR}/src/lbaselib.c
+    ${LUA_SOURCES_DIR}/src/ldblib.c
+    ${LUA_SOURCES_DIR}/src/liolib.c
+    ${LUA_SOURCES_DIR}/src/lmathlib.c
+    ${LUA_SOURCES_DIR}/src/loslib.c
+    ${LUA_SOURCES_DIR}/src/ltablib.c
     ${LUA_SOURCES_DIR}/src/lstrlib.c
+    ${LUA_SOURCES_DIR}/src/loadlib.c
+    ${LUA_SOURCES_DIR}/src/linit.c
     )
 
   add_library(Lua STATIC ${LUA_SOURCES})
diff -r b45bc565d82a -r 18fe778eeb95 Resources/Toolbox.lua
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/Toolbox.lua	Mon Apr 29 16:59:31 2013 +0200
@@ -0,0 +1,18 @@
+--[[ rPrint(struct, [limit], [indent])   Recursively print arbitrary data. 
+Set limit (default 100) to stanch infinite loops.
+Indents tables as [KEY] VALUE, nested tables as [KEY] [KEY]...[KEY] VALUE
+Set indent ("") to prefix each line:    Mytable [KEY] [KEY]...[KEY] VALUE
+https://gist.github.com/stuby/5445834#file-rprint-lua
+--]]
+function rPrint(s, l, i) -- recursive Print (structure, limit, indent)
+   l = (l) or 100; i = i or "";	-- default item limit, indent string
+   if (l<1) then print "ERROR: Item limit reached."; return l-1 end;
+   local ts = type(s);
+   if (ts ~= "table") then print (i,ts,s); return l-1 end
+   print (i,ts);           -- print "table"
+   for k,v in pairs(s) do  -- print "[KEY] VALUE"
+      l = rPrint(v, l, i.."\t["..tostring(k).."]");
+      if (l < 0) then break end
+   end
+   return l
+end