Commits

Martin Felis committed cc6abc3

updated LuaTables++

  • Participants
  • Parent commits 695022a

Comments (0)

Files changed (2)

File addons/luamodel/luatables.cc

 /*
  * LuaTables++
- * Copyright (c) 2011-2013 Martin Felis <martin@fyxs.org>.
+ * Copyright (c) 2013-2014 Martin Felis <martin@fyxs.org>.
  * All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining
    #include <lualib.h>
 }
 
+#include <stdio.h>  /* defines FILENAME_MAX */
+#ifdef WINDOWS
+    #include <direct.h>
+    #define get_current_dir _getcwd
+#else
+    #include <unistd.h>
+    #define get_current_dir getcwd
+ #endif
+
+#if defined(WIN32) || defined (_WIN32)
+#define DIRECTORY_SEPARATOR "\\"
+#elif defined(linux) || defined (__linux) || defined(__linux__) || defined(__APPLE__)
+#define DIRECTORY_SEPARATOR "/"
+#else
+#error Platform not supported!
+#endif
+
 using namespace std;
 
-const char* serialize_std = "function serialize (o, tabs)\n\
-  local result = \"\"\n\
-  \n\
-  if tabs == nil then\n\
-    tabs = \"\"\n\
-  end\n\
-\n\
-  if type(o) == \"number\" then\n\
-    result = result .. tostring(o)\n\
-  elseif type(o) == \"boolean\" then\n\
-    result = result .. tostring(o)\n\
-  elseif type(o) == \"string\" then\n\
-    result = result .. string.format(\"%q\", o)\n\
-  elseif type(o) == \"table\" then\n\
-    if o.dont_serialize_me then\n\
-      return \"{}\"\n\
-    end\n\
-    result = result .. \"{\\n\"\n\
-    for k,v in pairs(o) do\n\
-      if type(v) ~= \"function\" then\n\
-        -- make sure that numbered keys are properly are indexified\n\
-        if type(k) == \"number\" then\n\
-				  if type(v) == \"number\" then\n\
-	          result = result .. \" \" .. tostring(v) .. \",\"\n\
-					else\n\
-	          result = result .. tabs .. serialize(v, tabs .. \"  \") .. \",\\n\"\n\
-					end\n\
-        else\n\
-          result = result .. tabs .. \"  \" .. k .. \" = \" .. serialize(v, tabs .. \"  \") .. \",\\n\"\n\
-        end\n\
-      end\n\
-    end\n\
-    result = result .. tabs .. \"}\"\n\
-  else\n\
-    print (\"ignoring stuff\" .. type(o) )\n\
-  end\n\
-  return result\n\
-end\n\
-\n\
-return serialize";
+std::string get_file_directory (const char* filename) {
+	string name (filename);
+	string result = name.substr(0, name.find_last_of (DIRECTORY_SEPARATOR) + 1);
 
+	if (result == "")
+		result = "./";
+#if defined (WIN32) || defined (_WIN32)
+#warning get_file_directory() not yet tested under Windows!
+	else if (result.substr(1,2) != ":\\")
+		result = string(".\\") + result;
+#else
+	else if (result.substr(0,string(DIRECTORY_SEPARATOR).size()) != DIRECTORY_SEPARATOR  && result[0] != '.')
+		result = string("./") + result;
+#endif
+
+	return result;
+}
+
+// char encoded serialize function that is available in plaintext in
+// utils/serialize.lua. Converted using lua auto.lua serialize.lua
+const char serialize_std[] = {
+	0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69, 0x73, 0x6c, 0x69, 0x73, 0x74, 0x20, 0x28, 0x74, 
+	0x29, 0x0a,
+	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x69, 0x74, 0x65, 0x6d, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x3d, 
+	0x20, 0x30, 0x0a,
+	0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 
+	0x20, 0x6e, 0x69, 0x6c, 0x0a,
+	0x09, 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x70, 0x61, 0x69, 0x72, 0x73, 0x28, 
+	0x74, 0x29, 0x20, 0x64, 0x6f, 0x0a,
+	0x09, 0x09, 0x69, 0x74, 0x65, 0x6d, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x69, 0x74, 0x65, 0x6d, 
+	0x63, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x2b, 0x20, 0x31, 0x0a,
+	0x09, 0x09, 0x69, 0x66, 0x20, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x3d, 0x20, 
+	0x6e, 0x69, 0x6c, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x09, 0x09, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x79, 0x70, 
+	0x65, 0x28, 0x76, 0x29, 0x0a,
+	0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x6c, 0x61, 
+	0x73, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x28, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 
+	0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 
+	0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 
+	0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x7e, 0x3d, 0x20, 0x22, 
+	0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x09, 0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a,
+	0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x0a,
+	0x09, 0x09, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x20, 0x3d, 0x20, 0x74, 0x79, 0x70, 0x65, 
+	0x28, 0x76, 0x29, 0x0a,
+	0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x69, 0x66, 0x20, 0x69, 0x74, 0x65, 0x6d, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x20, 0x7e, 0x3d, 0x20, 0x23, 
+	0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 0x6c, 0x73, 0x65, 0x0a,
+	0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x74, 0x72, 0x75, 0x65, 0x0a,
+	0x65, 0x6e, 0x64, 0x0a,
+	0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 
+	0x20, 0x28, 0x6f, 0x2c, 0x20, 0x74, 0x61, 0x62, 0x73, 0x29, 0x0a,
+	0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x22, 
+	0x22, 0x0a,
+	0x20, 0x20, 0x0a,
+	0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x3d, 0x3d, 0x20, 0x6e, 0x69, 0x6c, 0x20, 0x74, 
+	0x68, 0x65, 0x6e, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x3d, 0x20, 0x22, 0x22, 0x0a,
+	0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29, 0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6e, 
+	0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 
+	0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x6f, 0x29, 0x0a,
+	0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29, 0x20, 0x3d, 
+	0x3d, 0x20, 0x22, 0x62, 0x6f, 0x6f, 0x6c, 0x65, 0x61, 0x6e, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 
+	0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x6f, 0x29, 0x0a,
+	0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29, 0x20, 0x3d, 
+	0x3d, 0x20, 0x22, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 
+	0x74, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 
+	0x28, 0x22, 0x25, 0x71, 0x22, 0x2c, 0x20, 0x6f, 0x29, 0x0a,
+	0x09, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29, 0x20, 0x3d, 0x3d, 
+	0x20, 0x22, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x69, 0x73, 0x6c, 0x69, 0x73, 
+	0x74, 0x28, 0x6f, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x09, 0x09, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 
+	0x2e, 0x2e, 0x20, 0x22, 0x7b, 0x22, 0x0a,
+	0x09, 0x09, 0x66, 0x6f, 0x72, 0x20, 0x69, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x69, 0x70, 0x61, 0x69, 0x72, 
+	0x73, 0x28, 0x6f, 0x29, 0x20, 0x64, 0x6f, 0x0a,
+	0x09, 0x09, 0x09, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 
+	0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 
+	0x67, 0x28, 0x76, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2c, 0x22, 0x0a,
+	0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x09, 0x09, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 
+	0x2e, 0x2e, 0x20, 0x22, 0x7d, 0x22, 0x0a,
+	0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6f, 0x29, 0x20, 0x3d, 
+	0x3d, 0x20, 0x22, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6f, 0x2e, 0x64, 0x6f, 0x6e, 0x74, 0x5f, 0x73, 0x65, 0x72, 0x69, 
+	0x61, 0x6c, 0x69, 0x7a, 0x65, 0x5f, 0x6d, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x7b, 0x7d, 0x22, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 
+	0x74, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x7b, 0x5c, 0x6e, 0x22, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x6b, 0x2c, 0x76, 0x20, 0x69, 0x6e, 0x20, 0x70, 0x61, 0x69, 
+	0x72, 0x73, 0x28, 0x6f, 0x29, 0x20, 0x64, 0x6f, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x7e, 
+	0x3d, 0x20, 0x22, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x6d, 0x61, 0x6b, 0x65, 0x20, 0x73, 0x75, 
+	0x72, 0x65, 0x20, 0x74, 0x68, 0x61, 0x74, 0x20, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x65, 0x64, 0x20, 0x6b, 
+	0x65, 0x79, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x6c, 0x79, 0x20, 0x61, 
+	0x72, 0x65, 0x20, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x69, 0x66, 0x69, 0x65, 0x64, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x6b, 0x29, 
+	0x20, 0x3d, 0x3d, 0x20, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x20, 0x20, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x76, 0x29, 0x20, 0x3d, 
+	0x3d, 0x20, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
+	0x09, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 
+	0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x22, 0x20, 0x2e, 0x2e, 
+	0x20, 0x74, 0x6f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x28, 0x76, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2c, 
+	0x22, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6c, 0x73, 0x65, 0x0a,
+	0x09, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 
+	0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e, 
+	0x2e, 0x20, 0x22, 0x20, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 
+	0x65, 0x28, 0x76, 0x2c, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x20, 0x22, 0x29, 
+	0x20, 0x2e, 0x2e, 0x20, 0x22, 0x2c, 0x5c, 0x6e, 0x22, 0x0a,
+	0x09, 0x09, 0x09, 0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 
+	0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e, 0x2e, 
+	0x20, 0x22, 0x20, 0x20, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x6b, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x3d, 0x20, 
+	0x22, 0x20, 0x2e, 0x2e, 0x20, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x28, 0x76, 0x2c, 0x20, 
+	0x74, 0x61, 0x62, 0x73, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x20, 0x20, 0x22, 0x29, 0x20, 0x2e, 0x2e, 0x20, 0x22, 
+	0x2c, 0x5c, 0x6e, 0x22, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x20, 0x3d, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 
+	0x74, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x61, 0x62, 0x73, 0x20, 0x2e, 0x2e, 0x20, 0x22, 0x7d, 0x22, 0x0a,
+	0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x20, 0x28, 0x22, 0x69, 0x67, 0x6e, 0x6f, 0x72, 0x69, 
+	0x6e, 0x67, 0x20, 0x73, 0x74, 0x75, 0x66, 0x66, 0x22, 0x20, 0x2e, 0x2e, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 
+	0x6f, 0x29, 0x20, 0x29, 0x0a,
+	0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x0a,
+	0x65, 0x6e, 0x64, 0x0a,
+	0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x0a,
+};
 //
 // Lua Helper Functions
 //
 	return result;
 }
 
+template<> float LuaTableNode::getDefault<float>(const float &default_value) {
+	float result = default_value;
+
+	if (stackQueryValue()) {
+		result = static_cast<float>(lua_tonumber (luaTable->L, -1));
+	}
+
+	stackRestore();
+
+	return result;
+}
+
 template<> double LuaTableNode::getDefault<double>(const double &default_value) {
 	double result = default_value;
 
 template<> std::string LuaTableNode::getDefault<std::string>(const std::string &default_value) {
 	std::string result = default_value;
 
-	if (stackQueryValue()) {
+	if (stackQueryValue() && lua_isstring(luaTable->L, -1)) {
 		result = lua_tostring (luaTable->L, -1);
 	}
 
 	stackRestore();
 }
 
+template<> void LuaTableNode::set<float>(const float &value) {
+	stackCreateValue();
+
+	l_push_LuaKey (luaTable->L, key);
+	lua_pushnumber(luaTable->L, static_cast<double>(value));
+	// stack: parent, key, value
+	lua_settable (luaTable->L, -3);
+
+	stackRestore();
+}
+
 template<> void LuaTableNode::set<double>(const double &value) {
 	stackCreateValue();
 
 	result.deleteLuaState = true;
 	luaL_openlibs(result.L);
 
+	// Add the directory of _filename to package.path
+	result.addSearchPath(get_file_directory (_filename).c_str());
+
+	// run the file we 
 	if (luaL_dofile (result.L, _filename)) {
 		bail (result.L, "Error running file: ");
 	}
 	return result;
 }
 
+void LuaTable::addSearchPath(const char* path) {
+	if (L == NULL) {
+		cerr << "Error: Cannot add search path: Lua state is not initialized!" << endl;
+		abort();
+	}
+
+	lua_getglobal(L, "package");
+	lua_getfield (L, -1, "path");
+	if (lua_type(L, -1) != LUA_TSTRING) {
+		cerr << "Error: could not get package.path!" << endl;
+		abort();
+	}
+
+	string package_path = lua_tostring (L, -1);
+	package_path = package_path + string(path) + "?.lua;";
+
+	lua_pushstring(L, package_path.c_str());
+	lua_setfield (L, -3, "path");
+
+	lua_pop(L, 2);
+}
+
 std::string LuaTable::serialize() {
 	std::string result;
 
 
 	return result;
 }
-
-

File addons/luamodel/luatables.h

 /*
  * LuaTables++
- * Copyright (c) 2011-2013 Martin Felis <martin@fyxs.org>.
+ * Copyright (c) 2013-2014 Martin Felis <martin@fyxs.org>.
  * All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining
 
 template<> bool LuaTableNode::getDefault<bool>(const bool &default_value);
 template<> double LuaTableNode::getDefault<double>(const double &default_value);
+template<> float LuaTableNode::getDefault<float>(const float &default_value);
 template<> std::string LuaTableNode::getDefault<std::string>(const std::string &default_value);
 
 template<> void LuaTableNode::set<bool>(const bool &value);
+template<> void LuaTableNode::set<float>(const float &value);
 template<> void LuaTableNode::set<double>(const double &value);
 template<> void LuaTableNode::set<std::string>(const std::string &value);
 
 		return root_node;
 	}
 	int length();
+	void addSearchPath (const char* path);
 	std::string serialize ();
 
 	static LuaTable fromFile (const char *_filename);