Software /
code /
prosody
Annotate
util-src/signal.c @ 9656:3da6cc927ee6
util.format: Tweak how nil values are handled
Because [<nil>] seems exsessive
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 28 Nov 2018 20:36:53 +0100 |
parent | 9151:fee3933ff346 |
child | 10480:94cacf9fd0ae |
rev | line source |
---|---|
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 /* |
2405
88f73ee1c46f
util.signal: Update header comment for new filename
Matthew Wild <mwild1@gmail.com>
parents:
2343
diff
changeset
|
2 * signal.c -- Signal Handler Library for Lua |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 * |
2431
c4d32b35fe60
util.signal: Update version in header, and author's email
Matthew Wild <mwild1@gmail.com>
parents:
2430
diff
changeset
|
4 * Version: 1.000+changes |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 * |
2431
c4d32b35fe60
util.signal: Update version in header, and author's email
Matthew Wild <mwild1@gmail.com>
parents:
2430
diff
changeset
|
6 * Copyright (C) 2007 Patrick J. Donnelly (batrick@batbytes.com) |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 * This software is distributed under the same license as Lua 5.0: |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 * Permission is hereby granted, free of charge, to any person obtaining a |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 * copy of this software and associated documentation files (the "Software"), |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 * to deal in the Software without restriction, including without limitation |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 * and/or sell copies of the Software, and to permit persons to whom the |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 * Software is furnished to do so, subject to the following conditions: |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 * The above copyright notice and this permission notice shall be included |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 * in all copies or substantial portions of the Software. |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
26 * OTHER DEALINGS IN THE SOFTWARE. |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 */ |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
9150
c1d5f52274cf
net, pposix, signal: Check for redefined defines, fix warnings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8420
diff
changeset
|
29 #ifndef _GNU_SOURCE |
7973
703f7f45feb4
util.signal: Enable all GNU features, _DEFAULT_SOURCE doesn't have the desired effect before glibc 2.19
Kim Alvefur <zash@zash.se>
parents:
7971
diff
changeset
|
30 #define _GNU_SOURCE |
9150
c1d5f52274cf
net, pposix, signal: Check for redefined defines, fix warnings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
8420
diff
changeset
|
31 #endif |
7931
b619b85e01aa
util.pposix, configure: Move _GNU_SOURCE macro into source files
Kim Alvefur <zash@zash.se>
parents:
7889
diff
changeset
|
32 |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 #include <signal.h> |
2459
66f60e69567b
util.signal: Using stdlib.h instead of malloc.h.
Tobias Markmann <tm@ayena.de>
parents:
2432
diff
changeset
|
34 #include <stdlib.h> |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 #include "lua.h" |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 #include "lauxlib.h" |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
6789
6b180e77c97a
util-src/*.c: Invert Lua 5.2 compat to be 5.2+ by default and a macro to support 5.1
Kim Alvefur <zash@zash.se>
parents:
6620
diff
changeset
|
39 #if (LUA_VERSION_NUM == 501) |
6b180e77c97a
util-src/*.c: Invert Lua 5.2 compat to be 5.2+ by default and a macro to support 5.1
Kim Alvefur <zash@zash.se>
parents:
6620
diff
changeset
|
40 #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) |
6413
a552f4170aed
util-src/*.c: Add macro for compiling with Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
6412
diff
changeset
|
41 #endif |
a552f4170aed
util-src/*.c: Add macro for compiling with Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
6412
diff
changeset
|
42 |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 #ifndef lsig |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 #define lsig |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
47 struct lua_signal { |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
48 char *name; /* name of the signal */ |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
49 int sig; /* the signal */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 }; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 |
8414
7ea3311ca632
util.signal: Use a static array to keep track of pending signals (fixes #1029)
Kim Alvefur <zash@zash.se>
parents:
7973
diff
changeset
|
54 #define MAX_PENDING_SIGNALS 32 |
7ea3311ca632
util.signal: Use a static array to keep track of pending signals (fixes #1029)
Kim Alvefur <zash@zash.se>
parents:
7973
diff
changeset
|
55 |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 #define LUA_SIGNAL "lua_signal" |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 static const struct lua_signal lua_signals[] = { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
59 /* ANSI C signals */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 #ifdef SIGABRT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
61 {"SIGABRT", SIGABRT}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 #ifdef SIGFPE |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
64 {"SIGFPE", SIGFPE}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 #ifdef SIGILL |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
67 {"SIGILL", SIGILL}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 #ifdef SIGINT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
70 {"SIGINT", SIGINT}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 #ifdef SIGSEGV |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
73 {"SIGSEGV", SIGSEGV}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 #ifdef SIGTERM |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
76 {"SIGTERM", SIGTERM}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
78 /* posix signals */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 #ifdef SIGHUP |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
80 {"SIGHUP", SIGHUP}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 #ifdef SIGQUIT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
83 {"SIGQUIT", SIGQUIT}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 #ifdef SIGTRAP |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
86 {"SIGTRAP", SIGTRAP}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 #ifdef SIGKILL |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
89 {"SIGKILL", SIGKILL}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 #ifdef SIGUSR1 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
92 {"SIGUSR1", SIGUSR1}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 #ifdef SIGUSR2 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
95 {"SIGUSR2", SIGUSR2}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 #ifdef SIGPIPE |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
98 {"SIGPIPE", SIGPIPE}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 #ifdef SIGALRM |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
101 {"SIGALRM", SIGALRM}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 #ifdef SIGCHLD |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
104 {"SIGCHLD", SIGCHLD}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 #ifdef SIGCONT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
107 {"SIGCONT", SIGCONT}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 #ifdef SIGSTOP |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
110 {"SIGSTOP", SIGSTOP}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 #ifdef SIGTTIN |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
113 {"SIGTTIN", SIGTTIN}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 #ifdef SIGTTOU |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
116 {"SIGTTOU", SIGTTOU}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
118 /* some BSD signals */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 #ifdef SIGIOT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
120 {"SIGIOT", SIGIOT}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 #ifdef SIGBUS |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
123 {"SIGBUS", SIGBUS}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 #ifdef SIGCLD |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
126 {"SIGCLD", SIGCLD}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 #ifdef SIGURG |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
129 {"SIGURG", SIGURG}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 #ifdef SIGXCPU |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
132 {"SIGXCPU", SIGXCPU}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 #ifdef SIGXFSZ |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
135 {"SIGXFSZ", SIGXFSZ}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 #ifdef SIGVTALRM |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
138 {"SIGVTALRM", SIGVTALRM}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 #ifdef SIGPROF |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
141 {"SIGPROF", SIGPROF}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 #ifdef SIGWINCH |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
144 {"SIGWINCH", SIGWINCH}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 #ifdef SIGPOLL |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
147 {"SIGPOLL", SIGPOLL}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 #ifdef SIGIO |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
150 {"SIGIO", SIGIO}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
152 /* add odd signals */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 #ifdef SIGSTKFLT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
154 {"SIGSTKFLT", SIGSTKFLT}, /* stack fault */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 #ifdef SIGSYS |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
157 {"SIGSYS", SIGSYS}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
159 {NULL, 0} |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 }; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
162 static lua_State *Lsig = NULL; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 static lua_Hook Hsig = NULL; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 static int Hmask = 0; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 static int Hcount = 0; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 |
8414
7ea3311ca632
util.signal: Use a static array to keep track of pending signals (fixes #1029)
Kim Alvefur <zash@zash.se>
parents:
7973
diff
changeset
|
167 int signals[MAX_PENDING_SIGNALS]; |
7ea3311ca632
util.signal: Use a static array to keep track of pending signals (fixes #1029)
Kim Alvefur <zash@zash.se>
parents:
7973
diff
changeset
|
168 int nsig = 0; |
2430
69d377c84fe3
util.signal: Queue up multiple signals, instead of trampling on the previous debug hook (and never clearing our own)
Matthew Wild <mwild1@gmail.com>
parents:
2405
diff
changeset
|
169 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
170 static void sighook(lua_State *L, lua_Debug *ar) { |
9151
fee3933ff346
pposix, signal: Ignore unused arguments.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
9150
diff
changeset
|
171 (void)ar; |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
172 /* restore the old hook */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
173 lua_sethook(L, Hsig, Hmask, Hcount); |
2432
1e045b3e9dce
util.signal: Restore the old debug hook earlier, just in case we receive another signal between clearing the signal queue and restoring it
Matthew Wild <mwild1@gmail.com>
parents:
2431
diff
changeset
|
174 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
175 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
176 lua_gettable(L, LUA_REGISTRYINDEX); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 |
8420
fb27aff6d491
util.signal: Fix loop (fixes #1047)
Kim Alvefur <zash@zash.se>
parents:
8414
diff
changeset
|
178 for(int i = 0; i < nsig; i++) { |
8414
7ea3311ca632
util.signal: Use a static array to keep track of pending signals (fixes #1029)
Kim Alvefur <zash@zash.se>
parents:
7973
diff
changeset
|
179 lua_pushnumber(L, signals[i]); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
180 lua_gettable(L, -2); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
181 lua_call(L, 0, 0); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
182 }; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 |
8414
7ea3311ca632
util.signal: Use a static array to keep track of pending signals (fixes #1029)
Kim Alvefur <zash@zash.se>
parents:
7973
diff
changeset
|
184 nsig = 0; |
7ea3311ca632
util.signal: Use a static array to keep track of pending signals (fixes #1029)
Kim Alvefur <zash@zash.se>
parents:
7973
diff
changeset
|
185 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
186 lua_pop(L, 1); /* pop lua_signal table */ |
2430
69d377c84fe3
util.signal: Queue up multiple signals, instead of trampling on the previous debug hook (and never clearing our own)
Matthew Wild <mwild1@gmail.com>
parents:
2405
diff
changeset
|
187 |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 } |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
190 static void handle(int sig) { |
8414
7ea3311ca632
util.signal: Use a static array to keep track of pending signals (fixes #1029)
Kim Alvefur <zash@zash.se>
parents:
7973
diff
changeset
|
191 if(nsig == 0) { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
192 /* Store the existing debug hook (if any) and its parameters */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
193 Hsig = lua_gethook(Lsig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
194 Hmask = lua_gethookmask(Lsig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
195 Hcount = lua_gethookcount(Lsig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
196 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
197 /* Set our new debug hook */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
198 lua_sethook(Lsig, sighook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); |
8414
7ea3311ca632
util.signal: Use a static array to keep track of pending signals (fixes #1029)
Kim Alvefur <zash@zash.se>
parents:
7973
diff
changeset
|
199 } |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
200 |
8414
7ea3311ca632
util.signal: Use a static array to keep track of pending signals (fixes #1029)
Kim Alvefur <zash@zash.se>
parents:
7973
diff
changeset
|
201 if(nsig < MAX_PENDING_SIGNALS) { |
8420
fb27aff6d491
util.signal: Fix loop (fixes #1047)
Kim Alvefur <zash@zash.se>
parents:
8414
diff
changeset
|
202 signals[nsig++] = sig; |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
203 } |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 } |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 /* |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 * l_signal == signal(signal [, func [, chook]]) |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 * signal = signal number or string |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 * func = Lua function to call |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 * chook = catch within C functions |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 * if caught, Lua function _must_ |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 * exit, as the stack is most likely |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 * in an unstable state. |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
215 */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
217 static int l_signal(lua_State *L) { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
218 int args = lua_gettop(L); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
219 int t, sig; /* type, signal */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
220 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
221 /* get type of signal */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
222 luaL_checkany(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
223 t = lua_type(L, 1); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
225 if(t == LUA_TNUMBER) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
226 sig = (int) lua_tonumber(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
227 } else if(t == LUA_TSTRING) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
228 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
229 lua_gettable(L, LUA_REGISTRYINDEX); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
230 lua_pushvalue(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
231 lua_gettable(L, -2); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
232 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
233 if(!lua_isnumber(L, -1)) { |
6620
50eaefeec013
util-src/*.c: Per convention call luaL_error() as argument to return
Florian Zeitz <florob@babelmonkeys.de>
parents:
6615
diff
changeset
|
234 return luaL_error(L, "invalid signal string"); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
235 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
236 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
237 sig = (int) lua_tonumber(L, -1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
238 lua_pop(L, 1); /* get rid of number we pushed */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
239 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
240 luaL_checknumber(L, 1); /* will always error, with good error msg */ |
6620
50eaefeec013
util-src/*.c: Per convention call luaL_error() as argument to return
Florian Zeitz <florob@babelmonkeys.de>
parents:
6615
diff
changeset
|
241 return luaL_error(L, "unreachable: invalid number was accepted"); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
242 } |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
243 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
244 /* set handler */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
245 if(args == 1 || lua_isnil(L, 2)) { /* clear handler */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
246 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
247 lua_gettable(L, LUA_REGISTRYINDEX); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
248 lua_pushnumber(L, sig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
249 lua_gettable(L, -2); /* return old handler */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
250 lua_pushnumber(L, sig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
251 lua_pushnil(L); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
252 lua_settable(L, -4); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
253 lua_remove(L, -2); /* remove LUA_SIGNAL table */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
254 signal(sig, SIG_DFL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
255 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
256 luaL_checktype(L, 2, LUA_TFUNCTION); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
257 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
258 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
259 lua_gettable(L, LUA_REGISTRYINDEX); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
260 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
261 lua_pushnumber(L, sig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
262 lua_pushvalue(L, 2); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
263 lua_settable(L, -3); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
264 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
265 /* Set the state for the handler */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
266 Lsig = L; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
267 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
268 if(lua_toboolean(L, 3)) { /* c hook? */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
269 if(signal(sig, handle) == SIG_ERR) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
270 lua_pushboolean(L, 0); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
271 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
272 lua_pushboolean(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
273 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
274 } else { /* lua_hook */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
275 if(signal(sig, handle) == SIG_ERR) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
276 lua_pushboolean(L, 0); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
277 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
278 lua_pushboolean(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
279 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
280 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
281 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
282 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
283 return 1; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
284 } |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
285 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
286 /* |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
287 * l_raise == raise(signal) |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
288 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
289 * signal = signal number or string |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
290 */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
291 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
292 static int l_raise(lua_State *L) { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
293 /* int args = lua_gettop(L); */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
294 int t = 0; /* type */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
295 lua_Number ret; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
296 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
297 luaL_checkany(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
298 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
299 t = lua_type(L, 1); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
301 if(t == LUA_TNUMBER) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
302 ret = (lua_Number) raise((int) lua_tonumber(L, 1)); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
303 lua_pushnumber(L, ret); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
304 } else if(t == LUA_TSTRING) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
305 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
306 lua_gettable(L, LUA_REGISTRYINDEX); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
307 lua_pushvalue(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
308 lua_gettable(L, -2); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
309 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
310 if(!lua_isnumber(L, -1)) { |
6620
50eaefeec013
util-src/*.c: Per convention call luaL_error() as argument to return
Florian Zeitz <florob@babelmonkeys.de>
parents:
6615
diff
changeset
|
311 return luaL_error(L, "invalid signal string"); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
312 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
313 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
314 ret = (lua_Number) raise((int) lua_tonumber(L, -1)); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
315 lua_pop(L, 1); /* get rid of number we pushed */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
316 lua_pushnumber(L, ret); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
317 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
318 luaL_checknumber(L, 1); /* will always error, with good error msg */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
319 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
320 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
321 return 1; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 } |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
323 |
3282
8ef3beed0779
util.signal: Make kill() available on OS X (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
3274
diff
changeset
|
324 #if defined(__unix__) || defined(__APPLE__) |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
325 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
326 /* define some posix only functions */ |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
327 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
328 /* |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
329 * l_kill == kill(pid, signal) |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
330 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
331 * pid = process id |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
332 * signal = signal number or string |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
333 */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
334 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
335 static int l_kill(lua_State *L) { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
336 int t; /* type */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
337 lua_Number ret; /* return value */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
338 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
339 luaL_checknumber(L, 1); /* must be int for pid */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
340 luaL_checkany(L, 2); /* check for a second arg */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
341 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
342 t = lua_type(L, 2); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
343 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
344 if(t == LUA_TNUMBER) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
345 ret = (lua_Number) kill((int) lua_tonumber(L, 1), |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
346 (int) lua_tonumber(L, 2)); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
347 lua_pushnumber(L, ret); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
348 } else if(t == LUA_TSTRING) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
349 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
350 lua_gettable(L, LUA_REGISTRYINDEX); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
351 lua_pushvalue(L, 2); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
352 lua_gettable(L, -2); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
353 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
354 if(!lua_isnumber(L, -1)) { |
6620
50eaefeec013
util-src/*.c: Per convention call luaL_error() as argument to return
Florian Zeitz <florob@babelmonkeys.de>
parents:
6615
diff
changeset
|
355 return luaL_error(L, "invalid signal string"); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
356 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
357 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
358 ret = (lua_Number) kill((int) lua_tonumber(L, 1), |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
359 (int) lua_tonumber(L, -1)); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
360 lua_pop(L, 1); /* get rid of number we pushed */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
361 lua_pushnumber(L, ret); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
362 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
363 luaL_checknumber(L, 2); /* will always error, with good error msg */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
364 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
365 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
366 return 1; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
367 } |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
368 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
369 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
371 static const struct luaL_Reg lsignal_lib[] = { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
372 {"signal", l_signal}, |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
373 {"raise", l_raise}, |
3282
8ef3beed0779
util.signal: Make kill() available on OS X (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
3274
diff
changeset
|
374 #if defined(__unix__) || defined(__APPLE__) |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
375 {"kill", l_kill}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
376 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
377 {NULL, NULL} |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
378 }; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
379 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
380 int luaopen_util_signal(lua_State *L) { |
7818
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
6789
diff
changeset
|
381 #if (LUA_VERSION_NUM > 501) |
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
6789
diff
changeset
|
382 luaL_checkversion(L); |
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
6789
diff
changeset
|
383 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
384 int i = 0; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
385 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
386 /* add the library */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
387 lua_newtable(L); |
6789
6b180e77c97a
util-src/*.c: Invert Lua 5.2 compat to be 5.2+ by default and a macro to support 5.1
Kim Alvefur <zash@zash.se>
parents:
6620
diff
changeset
|
388 luaL_setfuncs(L, lsignal_lib, 0); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
389 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
390 /* push lua_signals table into the registry */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
391 /* put the signals inside the library table too, |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
392 * they are only a reference */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
393 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
394 lua_newtable(L); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
395 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
396 while(lua_signals[i].name != NULL) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
397 /* registry table */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
398 lua_pushstring(L, lua_signals[i].name); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
399 lua_pushnumber(L, lua_signals[i].sig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
400 lua_settable(L, -3); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
401 /* signal table */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
402 lua_pushstring(L, lua_signals[i].name); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
403 lua_pushnumber(L, lua_signals[i].sig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
404 lua_settable(L, -5); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
405 i++; |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
406 } |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
407 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
408 /* add newtable to the registry */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
409 lua_settable(L, LUA_REGISTRYINDEX); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
410 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
411 return 1; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
412 } |