1// Copyright 2025 International Digital Economy Academy
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15///|
16type Signal
17
18///|
19extern "c" fn uv_signal_make() -> type Signal
Signal = "moonbit_uv_signal_make"
20
21///|
22extern "c" fn uv_signal_init(uv : type Loop Bytes
Loop, signal : type Signal
Signal) -> Int
Int = "moonbit_uv_signal_init"
23
24///|
25pub fn type Signal
Signal::(self : Loop) -> Signal raise Errno
new(Loop
self : type Loop Bytes
Loop) -> type Signal
Signal raise type! Errno Status
Errno {
26 let Signal
signal = () -> Signal
uv_signal_make()
27 let Int
status = (uv : Loop, signal : Signal) -> Int
uv_signal_init(Loop
self, Signal
signal)
28 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
29 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
30 }
31 Signal
signal
32}
33
34///|
35extern "c" fn uv_signal_start(
36 signal : type Signal
Signal,
37 cb : (type Signal
Signal, Int
Int) -> Unit
Unit,
38 signum : Int
Int
39) -> Int
Int = "moonbit_uv_signal_start"
40
41///|
42pub fn type Signal
Signal::(self : Signal, cb : (Signal, Signum) -> Unit, signum : Signum) -> Unit raise Errno
start(
43 Signal
self : type Signal
Signal,
44 (Signal, Signum) -> Unit
cb : (type Signal
Signal, type Signum Int
Signum) -> Unit
Unit,
45 Signum
signum : type Signum Int
Signum
46) -> Unit
Unit raise type! Errno Status
Errno {
47 fn (Signal, Int) -> Unit
uv_cb(Signal
signal : type Signal
Signal, Int
signum : Int
Int) {
48 (Signal, Signum) -> Unit
cb(Signal
signal, Int
signum)
49 }
50
51 let Int
status = (signal : Signal, cb : (Signal, Int) -> Unit, signum : Int) -> Int
uv_signal_start(Signal
self, (Signal, Int) -> Unit
uv_cb, Signum
signum.(self : Signum) -> Int
Convert newtype to its underlying type, automatically derived.
inner())
52 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
53 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
54 }
55}
56
57///|
58extern "c" fn uv_signal_stop(signal : type Signal
Signal) -> Int
Int = "moonbit_uv_signal_stop"
59
60///|
61pub fn type Signal
Signal::(self : Signal) -> Unit raise Errno
stop(Signal
self : type Signal
Signal) -> Unit
Unit raise type! Errno Status
Errno {
62 let Int
status = (signal : Signal) -> Int
uv_signal_stop(Signal
self)
63 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
64 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
65 }
66}
67
68///|
69extern "c" fn uv_SIGHUP() -> Int
Int = "moonbit_uv_SIGHUP"
70
71///|
72let Int
_SIGHUP : Int
Int = () -> Int
uv_SIGHUP()
73
74///|
75extern "c" fn uv_SIGINT() -> Int
Int = "moonbit_uv_SIGINT"
76
77///|
78let Int
_SIGINT : Int
Int = () -> Int
uv_SIGINT()
79
80///|
81extern "c" fn uv_SIGQUIT() -> Int
Int = "moonbit_uv_SIGQUIT"
82
83///|
84let Int
_SIGQUIT : Int
Int = () -> Int
uv_SIGQUIT()
85
86///|
87extern "c" fn uv_SIGABRT() -> Int
Int = "moonbit_uv_SIGABRT"
88
89///|
90let Int
_SIGABRT : Int
Int = () -> Int
uv_SIGABRT()
91
92///|
93extern "c" fn uv_SIGTERM() -> Int
Int = "moonbit_uv_SIGTERM"
94
95///|
96let Int
_SIGTERM : Int
Int = () -> Int
uv_SIGTERM()
97
98///|
99extern "c" fn uv_SIGWINCH() -> Int
Int = "moonbit_uv_SIGWINCH"
100
101///|
102let Int
_SIGWINCH : Int
Int = () -> Int
uv_SIGWINCH()
103
104///|
105extern "c" fn uv_SIGPIPE() -> Int
Int = "moonbit_uv_SIGPIPE"
106
107///|
108let Int
_SIGPIPE : Int
Int = () -> Int
uv_SIGPIPE()
109
110///|
111type Signum Int
Int
112
113///|
114pub fn type Signum Int
Signum::() -> Signum
sighup() -> type Signum Int
Signum {
115 Int
_SIGHUP
116}
117
118///|
119pub fn type Signum Int
Signum::() -> Signum
sigint() -> type Signum Int
Signum {
120 Int
_SIGINT
121}
122
123///|
124pub fn type Signum Int
Signum::() -> Signum
sigquit() -> type Signum Int
Signum {
125 Int
_SIGQUIT
126}
127
128///|
129pub fn type Signum Int
Signum::() -> Signum
sigabrt() -> type Signum Int
Signum {
130 Int
_SIGABRT
131}
132
133///|
134pub fn type Signum Int
Signum::() -> Signum
sigterm() -> type Signum Int
Signum {
135 Int
_SIGTERM
136}
137
138///|
139pub fn type Signum Int
Signum::() -> Signum
sigwinch() -> type Signum Int
Signum {
140 Int
_SIGWINCH
141}
142
143///|
144pub fn type Signum Int
Signum::() -> Signum raise Errno
sigpipe() -> type Signum Int
Signum raise type! Errno Status
Errno {
145 if Int
_SIGPIPE (self : Int, other : Int) -> Bool
Compares two integers for equality.
Parameters:
self : The first integer to compare.
other : The second integer to compare.
Returns true if both integers have the same value, false otherwise.
Example:
inspect(42 == 42, content="true")
inspect(42 == -42, content="false")
== -1 {
146 raise (Status) -> Errno
Errno(Status
ENOSYS)
147 }
148 Int
_SIGPIPE
149}
150