diff options
Diffstat (limited to 'vendor/luasocket/src/except.h')
-rw-r--r-- | vendor/luasocket/src/except.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/luasocket/src/except.h b/vendor/luasocket/src/except.h new file mode 100644 index 00000000..71c31fd4 --- /dev/null +++ b/vendor/luasocket/src/except.h | |||
@@ -0,0 +1,46 @@ | |||
1 | #ifndef EXCEPT_H | ||
2 | #define EXCEPT_H | ||
3 | /*=========================================================================*\ | ||
4 | * Exception control | ||
5 | * LuaSocket toolkit (but completely independent from other modules) | ||
6 | * | ||
7 | * This provides support for simple exceptions in Lua. During the | ||
8 | * development of the HTTP/FTP/SMTP support, it became aparent that | ||
9 | * error checking was taking a substantial amount of the coding. These | ||
10 | * function greatly simplify the task of checking errors. | ||
11 | * | ||
12 | * The main idea is that functions should return nil as their first return | ||
13 | * values when they find an error, and return an error message (or value) | ||
14 | * following nil. In case of success, as long as the first value is not nil, | ||
15 | * the other values don't matter. | ||
16 | * | ||
17 | * The idea is to nest function calls with the "try" function. This function | ||
18 | * checks the first value, and, if it's falsy, wraps the second value in a | ||
19 | * table with metatable and calls "error" on it. Otherwise, it returns all | ||
20 | * values it received. Basically, it works like the Lua "assert" function, | ||
21 | * but it creates errors targeted specifically at "protect". | ||
22 | * | ||
23 | * The "newtry" function is a factory for "try" functions that call a | ||
24 | * finalizer in protected mode before calling "error". | ||
25 | * | ||
26 | * The "protect" function returns a new function that behaves exactly like | ||
27 | * the function it receives, but the new function catches exceptions thrown | ||
28 | * by "try" functions and returns nil followed by the error message instead. | ||
29 | * | ||
30 | * With these three functions, it's easy to write functions that throw | ||
31 | * exceptions on error, but that don't interrupt the user script. | ||
32 | \*=========================================================================*/ | ||
33 | |||
34 | #include "luasocket.h" | ||
35 | |||
36 | #ifndef _WIN32 | ||
37 | #pragma GCC visibility push(hidden) | ||
38 | #endif | ||
39 | |||
40 | int except_open(lua_State *L); | ||
41 | |||
42 | #ifndef _WIN32 | ||
43 | #pragma GCC visibility pop | ||
44 | #endif | ||
45 | |||
46 | #endif | ||