|
1 #ifndef SPBOT_NEXUS_LUA_H |
|
2 #define SPBOT_NEXUS_LUA_H |
|
3 |
|
4 /** |
|
5 * @file |
|
6 * |
|
7 * Defines the lua environment for use with nexus |
|
8 */ |
|
9 struct nexus_lua; |
|
10 |
|
11 #include "nexus.h" |
|
12 |
|
13 #include <lua5.1/lua.h> |
|
14 |
|
15 /** |
|
16 * The global lua state |
|
17 */ |
|
18 struct nexus_lua { |
|
19 /** The nexus we are operating on */ |
|
20 struct nexus *nexus; |
|
21 |
|
22 /** The main lua state */ |
|
23 lua_State *st; |
|
24 }; |
|
25 |
|
26 /** |
|
27 * Create a new lua state for nexus |
|
28 */ |
|
29 err_t nexus_lua_create (struct nexus_lua **lua_ptr, struct nexus *nexus, error_t *err); |
|
30 |
|
31 /** |
|
32 * Destroy the lua state |
|
33 */ |
|
34 void nexus_lua_destroy (struct nexus_lua *lua); |
|
35 |
|
36 /** |
|
37 * Parse and execute the given lua chunk in the nexus's lua context. |
|
38 * |
|
39 * This operation is equally valid for both textual and binary chunks, but this is intended for textual chunks, and |
|
40 * hence accepts a NUL-terminated string. |
|
41 * |
|
42 * This runs the chunk in the main lua state, so this will fail for any coroutine functions. |
|
43 */ |
|
44 err_t nexus_lua_eval (struct nexus_lua *lua, const char *chunk, error_t *err); |
|
45 |
|
46 /** |
|
47 * Handle a Lua error by converting the given error code into a ERR_LUA_* code, inspecting the error object at |
|
48 * the top of the stack. |
|
49 * |
|
50 * Please note that the resulting error_info points into strings inside the lua stack - once you pop the error, the |
|
51 * error_info might not be valid anymore after the next GC cycle. |
|
52 */ |
|
53 err_t nexus_lua_error (lua_State *L, int ret, error_t *err); |
|
54 |
|
55 #endif /* SPBOT_NEXUS_LUA_H */ |