author | Tero Marttila <terom@fixme.fi> |
Wed, 27 May 2009 23:57:48 +0300 | |
branch | new-lib-errors |
changeset 217 | 7728d6ec3abf |
parent 202 | 210c43e6c088 |
permissions | -rw-r--r-- |
105
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
#ifndef NEXUS_LUA_H |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
#define NEXUS_LUA_H |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
|
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
/** |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
* @file |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
6 |
* |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
* Defines the lua environment for use with nexus |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
*/ |
116
92e71129074d
split off lua_irc from lua_objs
Tero Marttila <terom@fixme.fi>
parents:
106
diff
changeset
|
9 |
struct nexus_lua; |
92e71129074d
split off lua_irc from lua_objs
Tero Marttila <terom@fixme.fi>
parents:
106
diff
changeset
|
10 |
|
105
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
#include "nexus.h" |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
12 |
|
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
13 |
#include <lua5.1/lua.h> |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
14 |
|
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
15 |
/** |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
16 |
* The global lua state |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
17 |
*/ |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
18 |
struct nexus_lua { |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
19 |
/** The nexus we are operating on */ |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
20 |
struct nexus *nexus; |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
21 |
|
202
210c43e6c088
slight tweaks to nexus_lua, use error_t and no need to pop the loaded chunk ourselv - lua_pcall will always do that
Tero Marttila <terom@fixme.fi>
parents:
136
diff
changeset
|
22 |
/** The main lua state */ |
105
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
23 |
lua_State *st; |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
24 |
}; |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
25 |
|
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
/** |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
27 |
* Create a new lua state for nexus |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
*/ |
217 | 29 |
err_t nexus_lua_create (struct nexus_lua **lua_ptr, struct nexus *nexus, error_t *err); |
105
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
30 |
|
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
31 |
/** |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
32 |
* Destroy the lua state |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
33 |
*/ |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
34 |
void nexus_lua_destroy (struct nexus_lua *lua); |
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
35 |
|
106
f00661136ac2
add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents:
105
diff
changeset
|
36 |
/** |
136 | 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. |
|
202
210c43e6c088
slight tweaks to nexus_lua, use error_t and no need to pop the loaded chunk ourselv - lua_pcall will always do that
Tero Marttila <terom@fixme.fi>
parents:
136
diff
changeset
|
41 |
* |
210c43e6c088
slight tweaks to nexus_lua, use error_t and no need to pop the loaded chunk ourselv - lua_pcall will always do that
Tero Marttila <terom@fixme.fi>
parents:
136
diff
changeset
|
42 |
* This runs the chunk in the main lua state, so this will fail for any coroutine functions. |
136 | 43 |
*/ |
202
210c43e6c088
slight tweaks to nexus_lua, use error_t and no need to pop the loaded chunk ourselv - lua_pcall will always do that
Tero Marttila <terom@fixme.fi>
parents:
136
diff
changeset
|
44 |
err_t nexus_lua_eval (struct nexus_lua *lua, const char *chunk, error_t *err); |
136 | 45 |
|
46 |
/** |
|
106
f00661136ac2
add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents:
105
diff
changeset
|
47 |
* Handle a Lua error by converting the given error code into a ERR_LUA_* code, inspecting the error object at |
f00661136ac2
add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents:
105
diff
changeset
|
48 |
* the top of the stack. |
f00661136ac2
add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents:
105
diff
changeset
|
49 |
* |
f00661136ac2
add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents:
105
diff
changeset
|
50 |
* Please note that the resulting error_info points into strings inside the lua stack - once you pop the error, the |
136 | 51 |
* error_info might not be valid anymore after the next GC cycle. |
106
f00661136ac2
add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents:
105
diff
changeset
|
52 |
*/ |
202
210c43e6c088
slight tweaks to nexus_lua, use error_t and no need to pop the loaded chunk ourselv - lua_pcall will always do that
Tero Marttila <terom@fixme.fi>
parents:
136
diff
changeset
|
53 |
err_t nexus_lua_error (lua_State *L, int ret, error_t *err); |
106
f00661136ac2
add nexus_lua_error for unified LUA_ERR* -> ERR_LUA_* mapping, and lua configuration support
Tero Marttila <terom@fixme.fi>
parents:
105
diff
changeset
|
54 |
|
105
b6b183fbf373
implement a separate nexus_lua module
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
55 |
#endif /* NEXUS_LUA_H */ |