Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move parts of the kernel to the right subdir
[simgrid.git] / src / bindings / lua / lua_private.h
index e6b393e..dfeccf1 100644 (file)
@@ -6,8 +6,13 @@
 
 /* SimGrid Lua bindings                                                     */
 
-#include "simgrid_lua.h"
+#ifndef LUA_PRIVATE_H
+#define LUA_PRIVATE_H
+
 #include "simgrid/msg.h"
+#include "simgrid_lua.h"
+
+extern "C" {
 
 void sglua_register_host_functions(lua_State* L);
 msg_host_t sglua_check_host(lua_State* L, int index);
@@ -15,3 +20,15 @@ msg_host_t sglua_check_host(lua_State* L, int index);
 void sglua_register_platf_functions(lua_State* L);
 
 const char* sglua_get_msg_error(msg_error_t err);
+
+}
+
+#define lua_ensure(...) \
+  _XBT_IF_ONE_ARG(_lua_ensure_ARG1, _lua_ensure_ARGN, __VA_ARGS__)(__VA_ARGS__)
+#define _lua_ensure_ARG1(cond) \
+  _lua_ensure_ARGN(cond, "Assertion %s failed", #cond)
+#define _lua_ensure_ARGN(cond, ...) \
+  do { if (!(cond)) { luaL_error(L, __VA_ARGS__); return -1;} } while (0)
+
+
+#endif /* LUA_PRIVATE_H */