Annotate

util-src/signal.c @ 7574:97b8506118a9

net.server_epoll: Fix missing quotes in logging call
author Kim Alvefur <zash@zash.se>
date Thu, 18 Aug 2016 02:30:49 +0200
parent 6789:6b180e77c97a
child 7818:54669df178c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 #include <signal.h>
2459
66f60e69567b util.signal: Using stdlib.h instead of malloc.h.
Tobias Markmann <tm@ayena.de>
parents: 2432
diff changeset
30 #include <stdlib.h>
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 #include "lua.h"
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 #include "lauxlib.h"
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34
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
35 #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
36 #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
37 #endif
a552f4170aed util-src/*.c: Add macro for compiling with Lua 5.2
Kim Alvefur <zash@zash.se>
parents: 6412
diff changeset
38
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 #ifndef lsig
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 #define lsig
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
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
43 struct 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
44 char* name; /* name of the 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
45 int sig; /* the signal */
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 };
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 #endif
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 #define LUA_SIGNAL "lua_signal"
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 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
53 /* ANSI C signals */
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 #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
55 {"SIGABRT", SIGABRT},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 #endif
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 #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
58 {"SIGFPE", SIGFPE},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 #endif
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 #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
61 {"SIGILL", SIGILL},
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 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
64 {"SIGINT", SIGINT},
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 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
67 {"SIGSEGV", SIGSEGV},
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 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
70 {"SIGTERM", SIGTERM},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 #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
72 /* posix signals */
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 #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
74 {"SIGHUP", SIGHUP},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 #endif
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 #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
77 {"SIGQUIT", SIGQUIT},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 #endif
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 #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
80 {"SIGTRAP", SIGTRAP},
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 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
83 {"SIGKILL", SIGKILL},
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 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
86 {"SIGUSR1", SIGUSR1},
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 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
89 {"SIGUSR2", SIGUSR2},
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 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
92 {"SIGPIPE", SIGPIPE},
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 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
95 {"SIGALRM", SIGALRM},
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 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
98 {"SIGCHLD", SIGCHLD},
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 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
101 {"SIGCONT", SIGCONT},
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 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
104 {"SIGSTOP", SIGSTOP},
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 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
107 {"SIGTTIN", SIGTTIN},
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 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
110 {"SIGTTOU", SIGTTOU},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 #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
112 /* some BSD signals */
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 #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
114 {"SIGIOT", SIGIOT},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 #endif
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 #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
117 {"SIGBUS", SIGBUS},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 #endif
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 #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
120 {"SIGCLD", SIGCLD},
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 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
123 {"SIGURG", SIGURG},
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 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
126 {"SIGXCPU", SIGXCPU},
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 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
129 {"SIGXFSZ", SIGXFSZ},
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 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
132 {"SIGVTALRM", SIGVTALRM},
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 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
135 {"SIGPROF", SIGPROF},
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 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
138 {"SIGWINCH", SIGWINCH},
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 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
141 {"SIGPOLL", SIGPOLL},
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 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
144 {"SIGIO", SIGIO},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 #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
146 /* add odd signals */
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 #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
148 {"SIGSTKFLT", SIGSTKFLT}, /* stack fault */
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 #endif
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 #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
151 {"SIGSYS", SIGSYS},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 #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
153 {NULL, 0}
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 };
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155
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
156 static lua_State* Lsig = NULL;
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 static lua_Hook Hsig = NULL;
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 static int Hmask = 0;
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 static int Hcount = 0;
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160
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
161 static struct signal_event {
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
162 int Nsig;
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
163 struct signal_event* next_event;
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
164 }* signal_queue = NULL;
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
165
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
166 static struct signal_event* last_event = NULL;
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
167
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
168 static void sighook(lua_State* L, lua_Debug* ar) {
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
169 struct signal_event* event;
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
170 /* 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
171 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
172
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
173 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
174 lua_gettable(L, LUA_REGISTRYINDEX);
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175
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
176 while((event = signal_queue)) {
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
177 lua_pushnumber(L, event->Nsig);
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
178 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
179 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
180 signal_queue = event->next_event;
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 free(event);
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
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
184 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
185
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 }
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187
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
188 static void handle(int 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
189 if(!signal_queue) {
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 /* 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
191 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
192 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
193 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
194
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 signal_queue = malloc(sizeof(struct signal_event));
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 signal_queue->Nsig = 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
197 signal_queue->next_event = NULL;
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198
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
199 last_event = signal_queue;
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
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
201 /* 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
202 lua_sethook(Lsig, sighook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 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
203 } 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
204 last_event->next_event = malloc(sizeof(struct signal_event));
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
205 last_event->next_event->Nsig = 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
206 last_event->next_event->next_event = 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
207
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
208 last_event = last_event->next_event;
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
209 }
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
210 }
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
211
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
212 /*
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
213 * l_signal == signal(signal [, func [, chook]])
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
214 *
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
215 * signal = signal number or string
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 * func = Lua function to call
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
217 * chook = catch within C functions
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
218 * if caught, Lua function _must_
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
219 * 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
220 * 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
221 */
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
222
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
223 static int l_signal(lua_State* 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
224 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
225 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
226
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 /* 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
228 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
229 t = lua_type(L, 1);
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
230
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
231 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
232 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
233 } 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
234 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
235 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
236 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
237 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
238
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 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
240 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
241 }
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
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
243 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
244 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
245 } 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
246 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
247 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
248 }
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
249
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
250 /* 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
251 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
252 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
253 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
254 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
255 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
256 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
257 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
258 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
259 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
260 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
261 } 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
262 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
263
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
264 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
265 lua_gettable(L, LUA_REGISTRYINDEX);
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
266
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
267 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
268 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
269 lua_settable(L, -3);
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
270
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
271 /* 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
272 Lsig = L;
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
273
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
274 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
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 } 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
281 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
282 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
283 } 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
284 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
285 }
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
286 }
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
287 }
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
288
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
289 return 1;
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
290 }
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
291
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
292 /*
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
293 * l_raise == raise(signal)
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
294 *
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
295 * 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
296 */
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
297
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
298 static int l_raise(lua_State* 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
299 /* 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
300 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
301 lua_Number ret;
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
302
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
303 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
304
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 t = lua_type(L, 1);
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
306
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
307 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
308 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
309 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
310 } 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
311 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
312 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
313 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
314 lua_gettable(L, -2);
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
315
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
316 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
317 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
318 }
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 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
321 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
322 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
323 } 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
324 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
325 }
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
326
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
327 return 1;
988
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
3282
8ef3beed0779 util.signal: Make kill() available on OS X (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 3274
diff changeset
330 #if defined(__unix__) || defined(__APPLE__)
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
331
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
332 /* define some posix only functions */
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
333
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
334 /*
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
335 * l_kill == kill(pid, signal)
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
336 *
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
337 * pid = process id
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
338 * 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
339 */
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
340
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
341 static int l_kill(lua_State* 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
342 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
343 lua_Number ret; /* return value */
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
344
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
345 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
346 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
347
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 t = lua_type(L, 2);
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
349
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
350 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
351 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
352 (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
353 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
354 } 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
355 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
356 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
357 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
358 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
359
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 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
361 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
362 }
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
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 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
365 (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
366 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
367 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
368 } 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
369 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
370 }
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
371
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 return 1;
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
373 }
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
374
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
375 #endif
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
376
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
377 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
378 {"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
379 {"raise", l_raise},
3282
8ef3beed0779 util.signal: Make kill() available on OS X (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents: 3274
diff changeset
380 #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
381 {"kill", l_kill},
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
382 #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
383 {NULL, NULL}
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
384 };
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 int luaopen_util_signal(lua_State* 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
387 int i = 0;
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
388
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
389 /* 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
390 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
391 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
392
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
393 /* 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
394 /* 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
395 * 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
396 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
397 lua_newtable(L);
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
398
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
399 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
400 /* 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
401 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
402 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
403 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
404 /* 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
405 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
406 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
407 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
408 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
409 }
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 /* 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
412 lua_settable(L, LUA_REGISTRYINDEX);
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
413
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
414 return 1;
988
8cb9a0d59e78 util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
415 }