Commits

Martin Felis committed 451889e Draft

updated to newer luatables library and allowing shorter single dof joints

Comments (0)

Files changed (4)

addons/luamodel/CMakeLists.txt

 	lua-5.2.1/src/lua.c
 	lua-5.2.1/src/lundump.c
 	lua-5.2.1/src/lvm.c
-	lua-5.2.1/src/lzio.c
+	lua-5.2.1/src/lzio.c	
 	)
 
 # Options
 ADD_LIBRARY ( rbdl_luamodel SHARED ${LUA_SOURCES} ${LUAMODEL_SOURCES} )
 
 IF (BUILD_STATIC)
-  ADD_LIBRARY ( rbdl_luamodel-static STATIC ${LUAMODEL_SOURCES} )
-  SET_TARGET_PROPERTIES ( rbdl_luamodel-static PROPERTIES PREFIX "lib")
-  SET_TARGET_PROPERTIES ( rbdl_luamodel-static PROPERTIES OUTPUT_NAME "rbdl_luamodel")
+	ADD_LIBRARY ( rbdl_luamodel-static STATIC ${LUAMODEL_SOURCES} )
+	SET_TARGET_PROPERTIES ( rbdl_luamodel-static PROPERTIES PREFIX "lib")
+	SET_TARGET_PROPERTIES ( rbdl_luamodel-static PROPERTIES OUTPUT_NAME "rbdl_luamodel")
 
 	TARGET_LINK_LIBRARIES (rbdl_luamodel-static
 		rbdl

addons/luamodel/luamodel.cc

 #include "rbdl.h"
 #include "luamodel.h"
 
-#include <assert.h>
 #include <iostream>
 #include <map>
 
 
 using namespace std;
 
-void bail(lua_State *L, const char *msg){
+static void bail(lua_State *L, const char *msg){
 	std::cerr << msg << lua_tostring(L, -1) << endl;
 	abort();
 }
 SpatialVector get_spatial_vector (lua_State *L, const string &path, int index = -1) {
 	SpatialVector result (0., 0., 0., 0., 0., 0.);
 
-	std::vector<double> array = get_array (L, path, index);
+	std::vector<double> array = ltGetDoubleArrayAt (L, path.c_str(), index);
 	if (array.size() != 6) {
 		cerr << "Invalid array size for spatial vector variable '" << path << "'." << endl;
 		abort();
 Vector3d get_vector3d (lua_State *L, const string &path, int index = -1) {
 	Vector3d result;
 
-	std::vector<double> array = get_array (L, path, index);
+	std::vector<double> array = ltGetDoubleArrayAt (L, path.c_str(), index);
 	if (array.size() != 3) {
 		cerr << "Invalid array size for 3d vector variable '" << path << "'." << endl;
 		abort();
 	Matrix3d result;
 
 	// two ways either as flat array or as a lua table with three columns
-	if (get_length (L, path, -1) == 3) {
+	if (ltGetLengthAt (L, path.c_str(), -1) == 3) {
 		Vector3d row = get_vector3d (L, path, 1);
 		result(0,0) = row[0];
 		result(0,1) = row[1];
 		return result;
 	}
 
-	std::vector<double> array = get_array (L, path, -1);
+	std::vector<double> array = ltGetDoubleArrayAt (L, path.c_str(), -1);
 	if (array.size() != 9) {
 		cerr << "Invalid array size for 3d matrix variable '" << path << "'." << endl;
 		abort();
 		std::string &body_name,
 		bool verbose) {
 
-	if (!value_exists (L, path + ".name") != 0.) {
+	if (!ltIsExisting (L, (path + ".name").c_str())) {
 		cerr << "Error: could not find required value '" << path << ".name'." << endl;
 		return false;
 	}
-	body_name = get_string (L, path + ".name");
+	body_name = ltGetString (L, (path + ".name").c_str());
 
-	if (!value_exists (L, path + ".parent") != 0.) {
+	if (!ltIsExisting (L, (path + ".parent").c_str())) {
 		cerr << "Error: could not find required value '" << path << ".parent' for body '" << body_name << "'." << endl;
 		return false;
 	}
 
-	string parent_frame = get_string (L, path + ".parent");
+	string parent_frame = ltGetString (L, (path + ".parent").c_str());
 
 	StringIntMap::iterator parent_iter = body_table_id_map.find (parent_frame);
 	if (parent_iter == body_table_id_map.end()) {
 	}
 
 	// create the joint_frame
-	if (get_pointer (L, path + ".joint_frame") == NULL) {
+	if (!ltIsExisting(L, (path + ".joint_frame").c_str())) {
 		joint_frame = SpatialTransform();
 	} else {
 		Vector3d r (0., 0., 0.);
 		Matrix3d E (Matrix3d::Identity(3,3));
 	
-		if (get_pointer (L, path + ".joint_frame.r") != NULL) {
+		if (ltIsExisting(L, (path + ".joint_frame.r").c_str())) {
 			r = get_vector3d (L, path + ".joint_frame.r");
 		}
 
-		if (get_pointer (L, path + ".joint_frame.E") != NULL) {
+		if (ltIsExisting(L, (path + ".joint_frame.E").c_str())) {
 			E = get_matrix3d (L, path + ".joint_frame.E");
 		}
 
 		cout << "  joint_frame = " << joint_frame << endl;
 
 	// create the joint
-	if (get_pointer (L, path + ".joint") == NULL) {
+	if (!ltIsExisting (L, (path + ".joint").c_str())) {
 		joint = Joint(JointTypeFixed);
 	} else {
-		unsigned int joint_dofs = static_cast<unsigned int> (get_length (L, path + ".joint"));
+		unsigned int joint_dofs = static_cast<unsigned int> (ltGetLength (L, (path + ".joint").c_str()));
 
-		if (verbose)
-			cout << "  joint_dofs   = " << joint_dofs << endl;
+		// special case: joint_dof specified as { X., X., X., X., X., X.}. In
+		if (ltIsNumberAt (L, (path + ".joint").c_str(), 1)
+				&& ltIsNumberAt (L, (path + ".joint").c_str(), 2)
+				&& ltIsNumberAt (L, (path + ".joint").c_str(), 3)
+				&& ltIsNumberAt (L, (path + ".joint").c_str(), 4)
+				&& ltIsNumberAt (L, (path + ".joint").c_str(), 5)
+				&& ltIsNumberAt (L, (path + ".joint").c_str(), 6) ) {
+			joint = Joint (get_spatial_vector (L, path + ".joint"));
+		} else {
+			// otherwise: joint_dof specified as { { DOF1}, { DOF2}, ... }. In
+			if (verbose)
+				cout << "  joint_dofs   = " << joint_dofs << endl;
 
-		switch (joint_dofs) {
-			case 0: joint = Joint(JointTypeFixed);
-							break;
-			case 1: joint = Joint(get_spatial_vector(L, path + ".joint", 1));
-							break;
-			case 2: joint = Joint(
-									get_spatial_vector(L, path + ".joint", 1),
-									get_spatial_vector(L, path + ".joint", 2)
-									);
-							break;
-			case 3: joint = Joint(
-									get_spatial_vector(L, path + ".joint", 1),
-									get_spatial_vector(L, path + ".joint", 2),
-									get_spatial_vector(L, path + ".joint", 3)
-									);
-							break;
-			case 4: joint = Joint(
-									get_spatial_vector(L, path + ".joint", 1),
-									get_spatial_vector(L, path + ".joint", 2),
-									get_spatial_vector(L, path + ".joint", 3),
-									get_spatial_vector(L, path + ".joint", 4)
-									);
-							break;
-			case 5: joint = Joint(
-									get_spatial_vector(L, path + ".joint", 1),
-									get_spatial_vector(L, path + ".joint", 2),
-									get_spatial_vector(L, path + ".joint", 3),
-									get_spatial_vector(L, path + ".joint", 4),
-									get_spatial_vector(L, path + ".joint", 5)
-									);
-							break;
-			case 6: joint = Joint(
-									get_spatial_vector(L, path + ".joint", 1),
-									get_spatial_vector(L, path + ".joint", 2),
-									get_spatial_vector(L, path + ".joint", 3),
-									get_spatial_vector(L, path + ".joint", 4),
-									get_spatial_vector(L, path + ".joint", 5),
-									get_spatial_vector(L, path + ".joint", 6)
-									);
-							break;
-			default:
-							cerr << "Invalid number of DOFs for joint in frame '" << path << ".joint'" << endl;
-							return false;
+			switch (joint_dofs) {
+				case 0: joint = Joint(JointTypeFixed);
+								break;
+				case 1: joint = Joint(get_spatial_vector(L, path + ".joint", 1));
+								break;
+				case 2: joint = Joint(
+										get_spatial_vector(L, path + ".joint", 1),
+										get_spatial_vector(L, path + ".joint", 2)
+										);
+								break;
+				case 3: joint = Joint(
+										get_spatial_vector(L, path + ".joint", 1),
+										get_spatial_vector(L, path + ".joint", 2),
+										get_spatial_vector(L, path + ".joint", 3)
+										);
+								break;
+				case 4: joint = Joint(
+										get_spatial_vector(L, path + ".joint", 1),
+										get_spatial_vector(L, path + ".joint", 2),
+										get_spatial_vector(L, path + ".joint", 3),
+										get_spatial_vector(L, path + ".joint", 4)
+										);
+								break;
+				case 5: joint = Joint(
+										get_spatial_vector(L, path + ".joint", 1),
+										get_spatial_vector(L, path + ".joint", 2),
+										get_spatial_vector(L, path + ".joint", 3),
+										get_spatial_vector(L, path + ".joint", 4),
+										get_spatial_vector(L, path + ".joint", 5)
+										);
+								break;
+				case 6: joint = Joint(
+										get_spatial_vector(L, path + ".joint", 1),
+										get_spatial_vector(L, path + ".joint", 2),
+										get_spatial_vector(L, path + ".joint", 3),
+										get_spatial_vector(L, path + ".joint", 4),
+										get_spatial_vector(L, path + ".joint", 5),
+										get_spatial_vector(L, path + ".joint", 6)
+										);
+								break;
+				default:
+								cerr << "Invalid number of DOFs for joint in frame '" << path << ".joint'" << endl;
+								return false;
+			}
 		}
 	}
 
-	if (get_pointer (L, path + ".body") == NULL) {
+	if (!ltIsExisting (L, (path + ".body").c_str())) {
 		body = Body();
 	} else {
 		double mass = 0.;
 		Vector3d com (0., 0., 0.);
 		Matrix3d inertia (Matrix3d::Zero(3,3));
 
-		if (value_exists (L, path + ".body.mass")) {
-			mass = get_number (L, path + ".body.mass");
+		if (ltIsExisting (L, (path + ".body.mass").c_str()) ) {
+			mass = ltGetDouble (L, (path + ".body.mass").c_str());
 		}
 
-		if (value_exists (L, path + ".body.com")) {
+		if (ltIsExisting (L, (path + ".body.com").c_str() )) {
 			com = get_vector3d (L, path + ".body.com");
 		}
 
-		if (value_exists (L, path + ".body.inertia")) {
+		if (ltIsExisting (L, (path + ".body.inertia").c_str() )) {
 			inertia = get_matrix3d (L, path + ".body.inertia");
 		}
 
 		bail (L, "Error running file: ");
 	}
 
-	if (value_exists(L, "gravity")) {
+	if (ltIsExisting (L, "gravity")) {
 		model->gravity = get_vector3d (L, "gravity");
 
 		if (verbose)
 			cout << "gravity = " << model->gravity.transpose() << endl;
 	}
 
-	vector<string> frame_names = get_keys (L, "frames");
+	vector<string> frame_names = ltGetKeys (L, "frames");
 
 	unsigned int parent_id;
 	Math::SpatialTransform joint_frame;

addons/luamodel/luatables.cc

 
 using namespace std;
 
-/** \brief Extracts a single token from a path string */
-static std::string path_get_next_token (std::string &path) {
-	std::string token = path;
-
-	bool is_index = false;
-	bool have_bracket = false;
-
-	if (token.find(".") != std::string::npos) {
-		token = token.substr(0, token.find("."));
-	}
-
-	if (token.find("[") != std::string::npos) {
-		have_bracket = true;
-
-		if (token.find("[") == 0) {
-			token = token.substr (token.find("[") + 1, token.find("]") - 1);
-			path = path.substr (token.size() + 2, path.size());
-		} else {
-			token = token.substr (0, token.find("["));
-			path = path.substr (token.size(), path.size());
-		}
-	} else {
-		if (path.size() > token.size())
-			path = path.substr (token.size() + 1, path.size());
-		else
-			path = "";
-	}
-
-	if (path[0] == '.')
-		path = path.substr (1, path.size());
-
-	return token;
+static void bail(lua_State *L, const char *msg){
+	std::cerr << msg << lua_tostring(L, -1) << endl;
+	abort();
 }
 
 /** \brief Puts a lua value at a given path with optional index onto the stack.
  * optional last parameter is used to ease iteration over multiple
  * elements.
  */
-bool get_table_from_path (lua_State *L, const string &path_str, int index) {
-	std::string path = path_str;
-	std::string token = path;
+bool get_table_from_path (lua_State *L, const char *path_str, int index = -1);
 
-	// backup of the current stack
-	int stack_top = lua_gettop(L);
 
-	do {
-		token = path_get_next_token (path);
+/* Proxy functions for ltXXXAt() calls */
+std::string ltGetString (lua_State *L, const char *path_str, const std::string &default_result) {
+	return ltGetStringAt (L, path_str, -1, default_result);
+}
 
-		istringstream convert (token);
-		int token_int;
-		if (!(convert >> token_int)) 
-			lua_pushstring(L, token.c_str());
-		else
-			lua_pushnumber (L, token_int);
+double ltGetDouble (lua_State *L, const char *path_str, const double &default_result) {
+	return ltGetDoubleAt (L, path_str, -1, default_result);
+}
 
-		lua_gettable (L, -2);
+size_t ltGetLength (lua_State *L, const char *path_str) {
+	return ltGetLengthAt (L, path_str, -1);
+}
 
-		if (path.size() == 0 && index > 0) {
-			lua_pushnumber (L, index);
-			lua_gettable (L, -2);
-		}
+std::vector<std::string> ltGetKeys (lua_State *L, const char *path_str) {
+	return ltGetKeysAt (L, path_str, -1);
+}
 
-		if (lua_isnil(L, -1)) {
-			// clean up the stack
-			lua_pop (L, lua_gettop(L) - stack_top);
-			return false;
-		}
+std::vector<double> ltGetDoubleArray (lua_State *L, const char *path_str) {
+	return ltGetDoubleArrayAt (L, path_str, -1);
+}
+/* Actual interesting code */
 
-	} while (path.size() > 0);
+bool ltOpenFile (lua_State **L, const char *filename) {
+	*L = luaL_newstate();
+	luaL_openlibs(*L);
+
+	if (luaL_loadfile (*L, filename) || lua_pcall (*L, 0, 1, 0)) {
+		bail (*L, "Error running file: ");
+		return false;
+	}
 
 	return true;
 }
 
-bool value_exists (lua_State *L, const std::string &path_str, int index) {
+void ltClose (lua_State **L) {
+	lua_close(*L);
+	*L = NULL;
+}
+
+std::string ltGetStringAt (lua_State *L, const char *path_str, int index, const std::string &default_result) {
+	std::string result;
+
 	int stack_top = lua_gettop(L);
 
-	if (!get_table_from_path(L, path_str, index)) {
-		return false;
-	}
-
-	lua_pop (L, lua_gettop(L) - stack_top);
-	return true;
-}
-
-std::string get_string (lua_State *L, const string &path_str, int index) {
-	std::string result;
-	
-	int stack_top = lua_gettop(L);
-
-	if (!get_table_from_path(L, path_str, index)) {
-		cout << "Error: could not find table '" << path_str;
-		if (index > 0)
-			cout << "[" << index << "]";
-		cout << "'." << endl;
-		return result;
-	}
+	if (!get_table_from_path(L, path_str, index)) 
+		return default_result;
 
 	if (!lua_isstring(L, -1)) {
 		cout << "Error: value at " << path_str;
 			cout << "[" << index << "]";
 		cout << " is not a string!" << endl;
 
-		return result;
+		return default_result;
 	}
 
 	result = lua_tostring(L, -1);
 	return result;
 }
 
-double get_number (lua_State *L, const string &path_str, int index) {
+double ltGetDoubleAt (lua_State *L, const char *path_str, int index, const double &default_result) {
 	double result;
 	
 	int stack_top = lua_gettop(L);
 
-	if (!get_table_from_path(L, path_str, index)) {
-		cout << "Error: could not find table '" << path_str;
-		if (index > 0)
-			cout << "[" << index << "]";
-		cout << "'." << endl;
-		return result;
-	}
-
+	if (!get_table_from_path(L, path_str, index)) 
+		return default_result;
 
 	if (!lua_isnumber(L, -1)) {
 		cout << "Error: value at " << path_str;
 			cout << "[" << index << "]";
 		cout << " is not a number!" << endl;
 
-		return result;
+		return default_result;
 	}
 
 	result = lua_tonumber(L, -1);
 	return result;
 }
 
-const void* get_pointer (lua_State *L, const string &path_str, int index) {
-	int stack_top = lua_gettop(L);
-
-	if (!get_table_from_path(L, path_str, index)) 
-		return NULL;
-
-	if (lua_isnil(L, -1)) {
-		return NULL;
-	}
-
-	const void* result = lua_topointer(L, -1);
-
-	// clean up the stack
-	lua_pop (L, lua_gettop(L) - stack_top);
-
-	return result;
-}
-
-size_t get_length (lua_State *L, const string &path_str, int index) {
+size_t ltGetLengthAt (lua_State *L, const char *path_str, int index) {
 	size_t result = 0;
 	
 	int stack_top = lua_gettop(L);
 
-	if (!get_table_from_path(L, path_str, index)) {
-		cout << "Error: could not find table '" << path_str;
-		if (index > 0)
-			cout << "[" << index << "]";
-		cout << "'." << endl;
+	if (!get_table_from_path(L, path_str, index)) 
 		return result;
-	}
 
 	result = lua_objlen (L, -1);
 
 	return result;
 }
 
-std::vector<double> get_array (lua_State *L, const string &path_str, int index) {
-	std::vector<double> result;
-	
-	int stack_top = lua_gettop(L);
-
-	if (!get_table_from_path(L, path_str, index)) {
-		cout << "Error: could not find table '" << path_str;
-		if (index > 0)
-			cout << "[" << index << "]";
-		cout << "'." << endl;
-		return result;
-	}
-
-	if (!lua_istable(L, -1)) {
-		cout << "Error: value at " << path_str;
-		if (index > 0)
-			cout << "[" << index << "]";
-		cout << " is not a table!" << endl;
-
-		// clean up the stack
-		lua_pop (L, lua_gettop(L) - stack_top);
-		return result;
-	}
-
-	lua_pushnil(L);
-
-	int i = 1;
-	while (lua_next(L, -2)) {
-		if (lua_isnumber (L, -1)) {
-			result.push_back (lua_tonumber(L, -1));
-		} else {
-			cout << "Error: values at " << path_str;
-			if (index > 0)
-				cout << "[" << index << "]";
-			cout << " are not numbers only!" << endl;
-
-			// clean up the stack
-			lua_pop (L, lua_gettop(L) - stack_top);
-			return std::vector<double>();
-		}
-		lua_pop(L, 1);
-		i++;
-	}
-
-	// clean up the stack
-	lua_pop (L, lua_gettop(L) - stack_top);
-
-	return result;
-}
-
-std::vector<string> get_keys (lua_State *L, const string &path_str, int index) {
+std::vector<std::string> ltGetKeysAt (lua_State *L, const char *path_str, int index) {
 	std::vector<string> result;
 	
 	int stack_top = lua_gettop(L);
 
-	if (!get_table_from_path(L, path_str, index)) {
-		cout << "Error: could not find table '" << path_str;
-		if (index > 0)
-			cout << "[" << index << "]";
-		cout << "'." << endl;
+	if (!get_table_from_path(L, path_str, index)) 
 		return result;
-	}
 
 	if (!lua_istable(L, -1)) {
 		cout << "Error: value at " << path_str;
 	return result;
 }
 
+std::vector<double> ltGetDoubleArrayAt (lua_State *L, const char *path_str, int index) {
+	std::vector<double> result;
+	
+	int stack_top = lua_gettop(L);
 
+	if (!get_table_from_path(L, path_str, index)) 
+		return result;
+
+	if (!lua_istable(L, -1)) {
+		cout << "Error: value at " << path_str;
+		if (index > 0)
+			cout << "[" << index << "]";
+		cout << " is not a table!" << endl;
+
+		// clean up the stack
+		lua_pop (L, lua_gettop(L) - stack_top);
+		return result;
+	}
+
+	lua_pushnil(L);
+
+	int i = 1;
+	while (lua_next(L, -2)) {
+		if (lua_isnumber (L, -1)) {
+			result.push_back (lua_tonumber(L, -1));
+		} else {
+			cout << "Error: values at " << path_str;
+			if (index > 0)
+				cout << "[" << index << "]";
+			cout << " are not numbers only!" << endl;
+
+			// clean up the stack
+			lua_pop (L, lua_gettop(L) - stack_top);
+			return std::vector<double>();
+		}
+		lua_pop(L, 1);
+		i++;
+	}
+
+	// clean up the stack
+	lua_pop (L, lua_gettop(L) - stack_top);
+
+	return result;
+}
+
+bool ltIsNumber (lua_State *L, const char *path_str) {
+	return ltIsNumberAt (L, path_str, -1);
+}
+
+bool ltIsNumberAt (lua_State *L, const char *path_str, int index) {
+	bool result = false;
+
+	int stack_top = lua_gettop(L);
+
+	if (!get_table_from_path(L, path_str, index)) 
+		result = false;
+
+	if (lua_isnumber(L, -1)) {
+		result = true;
+	}
+
+	// clean up the stack
+	lua_pop (L, lua_gettop(L) - stack_top);
+
+	return result;
+}
+
+bool ltIsExisting (lua_State *L, const char *path_str) {
+	return ltIsExistingAt (L, path_str, -1);
+}
+
+bool ltIsExistingAt (lua_State *L, const char *path_str, int index) {
+	int stack_top = lua_gettop(L);
+
+	if (!get_table_from_path(L, path_str, index)) {
+		return false;
+	}
+
+	lua_pop (L, lua_gettop(L) - stack_top);
+	return true;
+}
+
+/** \brief Extracts a single token from a path string */
+static std::string path_get_next_token (std::string &path) {
+	std::string token = path;
+
+	bool is_index = false;
+	bool have_bracket = false;
+
+	if (token.find(".") != std::string::npos) {
+		token = token.substr(0, token.find("."));
+	}
+
+	if (token.find("[") != std::string::npos) {
+		have_bracket = true;
+
+		if (token.find("[") == 0) {
+			token = token.substr (token.find("[") + 1, token.find("]") - 1);
+			path = path.substr (token.size() + 2, path.size());
+		} else {
+			token = token.substr (0, token.find("["));
+			path = path.substr (token.size(), path.size());
+		}
+	} else {
+		if (path.size() > token.size())
+			path = path.substr (token.size() + 1, path.size());
+		else
+			path = "";
+	}
+
+	if (path[0] == '.')
+		path = path.substr (1, path.size());
+
+	return token;
+}
+
+/** \brief Puts a lua value at a given path with optional index onto the stack.
+ *
+ * This function allows to navigate tables by specifying the path to an
+ * element just as within lua, e.g. "model.bodies[2].inertia[2][3]". The
+ * optional last parameter is used to ease iteration over multiple
+ * elements.
+ */
+bool get_table_from_path (lua_State *L, const char *path_str, int index) {
+	std::string path = path_str;
+	std::string token = path;
+
+	// backup of the current stack
+	int stack_top = lua_gettop(L);
+
+	do {
+		token = path_get_next_token (path);
+
+		istringstream convert (token);
+		int token_int;
+		if (!(convert >> token_int)) 
+			lua_pushstring(L, token.c_str());
+		else
+			lua_pushnumber (L, token_int);
+
+		lua_gettable (L, -2);
+
+		if (path.size() == 0 && index > 0) {
+			lua_pushnumber (L, index);
+			lua_gettable (L, -2);
+		}
+
+		if (lua_isnil(L, -1)) {
+			cout << "Error: could not find table '" << path_str;
+			if (path.size() == 0 && index > 0)
+				cout << "[" << index << "]";
+			cout << "'." << endl;
+			
+			// clean up the stack
+			lua_pop (L, lua_gettop(L) - stack_top);
+			return false;
+		}
+
+	} while (path.size() > 0);
+
+	return true;
+}

addons/luamodel/luatables.h

 /*
  * luatables
- * Copyright (c) 2011-2012 Martin Felis <martin.felis@iwr.uni-heidelberg.de>
- * 
- * (zlib license)
- * 
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- * 
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- * 
- *    1. The origin of this software must not be misrepresented; you must not
- *    claim that you wrote the original software. If you use this software
- *    in a product, an acknowledgment in the product documentation would be
- *    appreciated but is not required.
- * 
- *    2. Altered source versions must be plainly marked as such, and must not be
- *    misrepresented as being the original software.
- * 
- *    3. This notice may not be removed or altered from any source
- *    distribution.
+ * Copyright (c) 2011-2012 Martin Felis <martin.felis@iwr.uni-heidelberg.de>.
+ * All rights reserved.
+*
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
 #ifndef _LUATABLES_H
 #include <vector>
 #include <string>
 
-extern "C"
-{
-   #include <lua.h>
-   #include <lauxlib.h>
-   #include <lualib.h>
+extern "C" {
+#include <lua.h>
 }
 
-/** \brief Puts a lua value at a given path with optional index onto the stack.
- *
- * This function allows to navigate tables by specifying the path to an
- * element just as within lua, e.g. "model.bodies[2].inertia[2][3]". The
- * optional last parameter is used to ease iteration over multiple
- * elements.
- */
-bool get_table_from_path (lua_State *L, const std::string &path_str, int index = -1);
+bool ltOpenFile (lua_State **L, const char *filename);
+void ltClose (lua_State **L);
 
-bool value_exists (lua_State *L, const std::string &path_str, int index = -1);
+std::string ltGetStringAt (lua_State *L, const char *path_str, int index, const std::string &default_result = "");
+std::string ltGetString (lua_State *L, const char *path_str, const std::string &default_result = "");
 
-std::string get_string (lua_State *L, const std::string &path_str, int index = -1);
-double get_number (lua_State *L, const std::string &path_str, int index = -1);
-const void* get_pointer (lua_State *L, const std::string &path_str, int index = -1);
+double ltGetDoubleAt (lua_State *L, const char *path_str, int index, const double &default_result = 0.);
+double ltGetDouble (lua_State *L, const char *path_str, const double &default_result = 0.);
 
-size_t get_length (lua_State *L, const std::string &path_str, int index = -1);
+size_t ltGetLengthAt (lua_State *L, const char *path_str, int index);
+size_t ltGetLength (lua_State *L, const char *path_str);
 
-std::vector<double> get_array (lua_State *L, const std::string &path_str, int index = -1);
-std::vector<std::string> get_keys (lua_State *L, const std::string &path_str, int index = -1);
+std::vector<std::string> ltGetKeysAt (lua_State *L, const char *path_str, int index);
+std::vector<std::string> ltGetKeys (lua_State *L, const char *path_str);
+
+std::vector<double> ltGetDoubleArrayAt (lua_State *L, const char *path_str, int index);
+std::vector<double> ltGetDoubleArray (lua_State *L, const char *path_str); 
+
+bool ltIsNumber (lua_State *L, const char *path_str);
+bool ltIsNumberAt (lua_State *L, const char *path_str, int index);
+
+bool ltIsExisting (lua_State *L, const char *path_str);
+bool ltIsExistingAt (lua_State *L, const char *path_str, int index);
 
 /* _LUATABLES_H */
 #endif