src/spbot/nexus_lua.h
branchnew-lib-errors
changeset 218 5229a5d098b2
parent 217 7728d6ec3abf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/spbot/nexus_lua.h	Thu May 28 00:35:02 2009 +0300
@@ -0,0 +1,55 @@
+#ifndef SPBOT_NEXUS_LUA_H
+#define SPBOT_NEXUS_LUA_H
+
+/**
+ * @file
+ *
+ * Defines the lua environment for use with nexus
+ */
+struct nexus_lua;
+
+#include "nexus.h"
+
+#include <lua5.1/lua.h>
+
+/**
+ * The global lua state
+ */
+struct nexus_lua {
+    /** The nexus we are operating on */
+    struct nexus *nexus;
+
+    /** The main lua state */
+    lua_State *st;
+};
+
+/**
+ * Create a new lua state for nexus
+ */
+err_t nexus_lua_create (struct nexus_lua **lua_ptr, struct nexus *nexus, error_t *err);
+
+/**
+ * Destroy the lua state
+ */
+void nexus_lua_destroy (struct nexus_lua *lua);
+
+/**
+ * Parse and execute the given lua chunk in the nexus's lua context.
+ *
+ * This operation is equally valid for both textual and binary chunks, but this is intended for textual chunks, and
+ * hence accepts a NUL-terminated string.
+ *
+ * This runs the chunk in the main lua state, so this will fail for any coroutine functions.
+ */
+err_t nexus_lua_eval (struct nexus_lua *lua, const char *chunk, error_t *err);
+
+/**
+ * Handle a Lua error by converting the given error code into a ERR_LUA_* code, inspecting the error object at
+ * the top of the stack.
+ *
+ * Please note that the resulting error_info points into strings inside the lua stack - once you pop the error, the
+ * error_info might not be valid anymore after the next GC cycle.
+ */
+err_t nexus_lua_error (lua_State *L, int ret, error_t *err);
+
+#endif /* SPBOT_NEXUS_LUA_H */