changeset 384:18fe778eeb95 lua-scripting

wrapper around lua
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 29 Apr 2013 16:59:31 +0200
parents b45bc565d82a
children 7dec4f3c922c
files CMakeLists.txt Core/OrthancException.h Resources/CMake/LuaConfiguration.cmake Resources/Toolbox.lua
diffstat 4 files changed, 40 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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;
--- 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})
--- /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