Update.
This commit is contained in:
parent
90618f2336
commit
a830238d11
54
example/fswatch_demo.wren
vendored
Normal file
54
example/fswatch_demo.wren
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "fswatch" for FileWatcher, FsEvent
|
||||
import "timer" for Timer
|
||||
import "io" for File, FileFlags
|
||||
|
||||
System.print("=== FSWatch Module Demo ===\n")
|
||||
|
||||
var testFile = "/tmp/fswatch_demo.txt"
|
||||
|
||||
System.print("--- Setting up test file ---")
|
||||
var f = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.create | FileFlags.truncate)
|
||||
f.writeBytes("initial content", 0)
|
||||
f.close()
|
||||
System.print("Created test file: %(testFile)")
|
||||
|
||||
System.print("\n--- Starting file watcher ---")
|
||||
var watcher = FileWatcher.new(testFile)
|
||||
var eventCount = 0
|
||||
|
||||
watcher.start { |event|
|
||||
eventCount = eventCount + 1
|
||||
System.print("Event %(eventCount):")
|
||||
System.print(" Filename: %(event.filename)")
|
||||
System.print(" Is rename: %(event.isRename)")
|
||||
System.print(" Is change: %(event.isChange)")
|
||||
}
|
||||
|
||||
System.print("Watcher active: %(watcher.isActive)")
|
||||
|
||||
System.print("\n--- Modifying file ---")
|
||||
|
||||
Timer.immediate {
|
||||
var f2 = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.truncate)
|
||||
f2.writeBytes("first modification", 0)
|
||||
f2.close()
|
||||
System.print("Made first modification")
|
||||
}
|
||||
|
||||
Timer.sleep(150)
|
||||
|
||||
Timer.immediate {
|
||||
var f3 = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.truncate)
|
||||
f3.writeBytes("second modification", 0)
|
||||
f3.close()
|
||||
System.print("Made second modification")
|
||||
}
|
||||
|
||||
Timer.sleep(150)
|
||||
|
||||
System.print("\n--- Stopping watcher ---")
|
||||
watcher.stop()
|
||||
System.print("Watcher active: %(watcher.isActive)")
|
||||
System.print("Total events received: %(eventCount)")
|
||||
65
example/sysinfo_demo.wren
vendored
Normal file
65
example/sysinfo_demo.wren
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var formatBytes = Fn.new { |bytes|
|
||||
if (bytes < 1024) return "%(bytes) B"
|
||||
if (bytes < 1024 * 1024) return "%(((bytes / 1024) * 10).floor / 10) KB"
|
||||
if (bytes < 1024 * 1024 * 1024) return "%(((bytes / 1024 / 1024) * 10).floor / 10) MB"
|
||||
return "%(((bytes / 1024 / 1024 / 1024) * 10).floor / 10) GB"
|
||||
}
|
||||
|
||||
System.print("=== SysInfo Module Demo ===\n")
|
||||
|
||||
System.print("--- System Information ---")
|
||||
System.print("Hostname: %(SysInfo.hostname)")
|
||||
System.print("Uptime: %(SysInfo.uptime) seconds")
|
||||
|
||||
System.print("\n--- Memory Information ---")
|
||||
var total = SysInfo.totalMemory
|
||||
var free = SysInfo.freeMemory
|
||||
var used = total - free
|
||||
var resident = SysInfo.residentMemory
|
||||
var constrained = SysInfo.constrainedMemory
|
||||
|
||||
System.print("Total: %(formatBytes.call(total))")
|
||||
System.print("Free: %(formatBytes.call(free))")
|
||||
System.print("Used: %(formatBytes.call(used))")
|
||||
System.print("Process RSS: %(formatBytes.call(resident))")
|
||||
if (constrained > 0) {
|
||||
System.print("Constrained: %(formatBytes.call(constrained))")
|
||||
}
|
||||
|
||||
System.print("\n--- CPU Information ---")
|
||||
var cpus = SysInfo.cpuInfo
|
||||
System.print("CPU Count: %(cpus.count)")
|
||||
|
||||
for (i in 0...cpus.count) {
|
||||
var cpu = cpus[i]
|
||||
System.print(" CPU %(i): %(cpu["model"]) @ %(cpu["speed"]) MHz")
|
||||
}
|
||||
|
||||
System.print("\n--- Load Average ---")
|
||||
var load = SysInfo.loadAverage
|
||||
System.print("1 min: %(load[0])")
|
||||
System.print("5 min: %(load[1])")
|
||||
System.print("15 min: %(load[2])")
|
||||
|
||||
System.print("\n--- Network Interfaces ---")
|
||||
var interfaces = SysInfo.networkInterfaces
|
||||
for (name in interfaces.keys) {
|
||||
System.print("%(name):")
|
||||
for (addr in interfaces[name]) {
|
||||
System.print(" %(addr["family"]): %(addr["address"])")
|
||||
System.print(" Internal: %(addr["internal"])")
|
||||
System.print(" Netmask: %(addr["netmask"])")
|
||||
System.print(" MAC: %(addr["mac"])")
|
||||
}
|
||||
}
|
||||
|
||||
System.print("\n--- High Resolution Timer ---")
|
||||
var t1 = SysInfo.hrtime
|
||||
var t2 = SysInfo.hrtime
|
||||
System.print("Time 1: %(t1) ns")
|
||||
System.print("Time 2: %(t2) ns")
|
||||
System.print("Delta: %(t2 - t1) ns")
|
||||
60
example/udp_demo.wren
vendored
Normal file
60
example/udp_demo.wren
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "udp" for UdpSocket, UdpMessage
|
||||
import "timer" for Timer
|
||||
import "scheduler" for Scheduler
|
||||
|
||||
System.print("=== UDP Module Demo ===\n")
|
||||
|
||||
System.print("--- Basic UDP Echo Server ---")
|
||||
|
||||
var server = UdpSocket.new()
|
||||
server.bind("127.0.0.1", 8888)
|
||||
System.print("Server listening on %(server.localAddress):%(server.localPort)")
|
||||
|
||||
var client = UdpSocket.new()
|
||||
client.bind("127.0.0.1", 0)
|
||||
System.print("Client bound to %(client.localAddress):%(client.localPort)")
|
||||
|
||||
var messageCount = 0
|
||||
var maxMessages = 3
|
||||
|
||||
Scheduler.add {
|
||||
while (messageCount < maxMessages) {
|
||||
var msg = server.receive()
|
||||
if (msg == null) break
|
||||
|
||||
System.print("Server received: '%(msg[0])' from %(msg[1]):%(msg[2])")
|
||||
|
||||
server.send("Echo: %(msg[0])", msg[1], msg[2])
|
||||
messageCount = messageCount + 1
|
||||
}
|
||||
server.close()
|
||||
System.print("Server closed")
|
||||
}
|
||||
|
||||
Scheduler.add {
|
||||
var messages = ["Hello", "UDP", "World"]
|
||||
for (m in messages) {
|
||||
client.send(m, "127.0.0.1", 8888)
|
||||
System.print("Client sent: '%(m)'")
|
||||
|
||||
var response = client.receive()
|
||||
if (response != null) {
|
||||
System.print("Client received: '%(response[0])'")
|
||||
}
|
||||
}
|
||||
client.close()
|
||||
System.print("Client closed")
|
||||
}
|
||||
|
||||
Timer.sleep(500)
|
||||
|
||||
System.print("\n--- Broadcast Configuration ---")
|
||||
var bcast = UdpSocket.new()
|
||||
bcast.bind("0.0.0.0", 0)
|
||||
bcast.setBroadcast(true)
|
||||
System.print("Broadcast enabled on port %(bcast.localPort)")
|
||||
bcast.close()
|
||||
|
||||
System.print("\nDemo complete!")
|
||||
@ -42,46 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="argparse.html" class="active">argparse</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html" class="active">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html" class="active">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,46 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html" class="active">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html" class="active">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html" class="active">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html" class="active">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html" class="active">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html" class="active">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@ -290,8 +312,8 @@ if (dbUrl != null) {
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="os.html" class="prev">os</a>
|
||||
<a href="signal.html" class="next">signal</a>
|
||||
<a href="dns.html" class="prev">dns</a>
|
||||
<a href="fswatch.html" class="next">fswatch</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
369
manual/api/fswatch.html
Normal file
369
manual/api/fswatch.html
Normal file
@ -0,0 +1,369 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- retoor <retoor@molodetz.nl> -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>fswatch - Wren-CLI Manual</title>
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<button class="mobile-menu-toggle">Menu</button>
|
||||
<div class="container">
|
||||
<aside class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h1><a href="../index.html">Wren-CLI</a></h1>
|
||||
<div class="version">v0.4.0</div>
|
||||
</div>
|
||||
<nav class="sidebar-nav">
|
||||
<div class="section">
|
||||
<span class="section-title">Getting Started</span>
|
||||
<ul>
|
||||
<li><a href="../getting-started/index.html">Overview</a></li>
|
||||
<li><a href="../getting-started/installation.html">Installation</a></li>
|
||||
<li><a href="../getting-started/first-script.html">First Script</a></li>
|
||||
<li><a href="../getting-started/repl.html">Using the REPL</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Language</span>
|
||||
<ul>
|
||||
<li><a href="../language/index.html">Syntax Overview</a></li>
|
||||
<li><a href="../language/classes.html">Classes</a></li>
|
||||
<li><a href="../language/methods.html">Methods</a></li>
|
||||
<li><a href="../language/control-flow.html">Control Flow</a></li>
|
||||
<li><a href="../language/fibers.html">Fibers</a></li>
|
||||
<li><a href="../language/modules.html">Modules</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">API Reference</span>
|
||||
<ul>
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html" class="active">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
</aside>
|
||||
<main class="content">
|
||||
<nav class="breadcrumb">
|
||||
<a href="../index.html">Home</a>
|
||||
<span class="separator">/</span>
|
||||
<a href="index.html">API Reference</a>
|
||||
<span class="separator">/</span>
|
||||
<span>fswatch</span>
|
||||
</nav>
|
||||
|
||||
<article>
|
||||
<h1>fswatch</h1>
|
||||
|
||||
<p>The <code>fswatch</code> module provides file system watching capabilities, allowing scripts to monitor files and directories for changes in real-time. Built on libuv's filesystem events.</p>
|
||||
|
||||
<pre><code>import "fswatch" for FileWatcher, FsEvent</code></pre>
|
||||
|
||||
<div class="toc">
|
||||
<h4>On This Page</h4>
|
||||
<ul>
|
||||
<li><a href="#filewatcher-class">FileWatcher Class</a></li>
|
||||
<li><a href="#fsevent-class">FsEvent Class</a></li>
|
||||
<li><a href="#examples">Examples</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<h2 id="filewatcher-class">FileWatcher Class</h2>
|
||||
|
||||
<div class="class-header">
|
||||
<h3>FileWatcher</h3>
|
||||
<p>Monitors a file or directory for changes</p>
|
||||
</div>
|
||||
|
||||
<h3>Constructor</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">FileWatcher.new</span>(<span class="param">path</span>) → <span class="type">FileWatcher</span>
|
||||
</div>
|
||||
<p>Creates a new FileWatcher for the specified path. The path can be a file or directory.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">path</span> <span class="param-type">(String)</span> - Path to the file or directory to watch</li>
|
||||
</ul>
|
||||
<pre><code>var watcher = FileWatcher.new("./config.json")
|
||||
var dirWatcher = FileWatcher.new("./src")</code></pre>
|
||||
|
||||
<h3>Methods</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">start</span>(<span class="param">callback</span>)
|
||||
</div>
|
||||
<p>Starts watching for changes. The callback function is invoked with an FsEvent whenever a change is detected.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">callback</span> <span class="param-type">(Fn)</span> - Function that receives an FsEvent parameter</li>
|
||||
</ul>
|
||||
<pre><code>watcher.start { |event|
|
||||
System.print("Changed: %(event.filename)")
|
||||
}</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">stop</span>()
|
||||
</div>
|
||||
<p>Stops watching for changes.</p>
|
||||
<pre><code>watcher.stop()</code></pre>
|
||||
|
||||
<h3>Properties</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">isActive</span> → <span class="type">Bool</span>
|
||||
</div>
|
||||
<p>Returns true if the watcher is currently active.</p>
|
||||
<pre><code>if (watcher.isActive) {
|
||||
System.print("Watcher is running")
|
||||
}</code></pre>
|
||||
|
||||
<h2 id="fsevent-class">FsEvent Class</h2>
|
||||
|
||||
<div class="class-header">
|
||||
<h3>FsEvent</h3>
|
||||
<p>Represents a file system change event</p>
|
||||
</div>
|
||||
|
||||
<h3>Properties</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">filename</span> → <span class="type">String</span>
|
||||
</div>
|
||||
<p>The name of the file that changed. For directory watchers, this is the relative filename within the directory.</p>
|
||||
<pre><code>System.print("File changed: %(event.filename)")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">isRename</span> → <span class="type">Bool</span>
|
||||
</div>
|
||||
<p>True if the event is a rename/move operation. This includes file creation and deletion.</p>
|
||||
<pre><code>if (event.isRename) {
|
||||
System.print("File renamed/created/deleted")
|
||||
}</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">isChange</span> → <span class="type">Bool</span>
|
||||
</div>
|
||||
<p>True if the event is a content change.</p>
|
||||
<pre><code>if (event.isChange) {
|
||||
System.print("File content modified")
|
||||
}</code></pre>
|
||||
|
||||
<h2 id="examples">Examples</h2>
|
||||
|
||||
<h3>Watch a Single File</h3>
|
||||
<pre><code>import "fswatch" for FileWatcher
|
||||
|
||||
var watcher = FileWatcher.new("./config.json")
|
||||
|
||||
watcher.start { |event|
|
||||
System.print("Config changed!")
|
||||
System.print(" Rename: %(event.isRename)")
|
||||
System.print(" Change: %(event.isChange)")
|
||||
}
|
||||
|
||||
System.print("Watching config.json for changes...")
|
||||
System.print("Press Ctrl+C to stop")</code></pre>
|
||||
|
||||
<h3>Watch a Directory</h3>
|
||||
<pre><code>import "fswatch" for FileWatcher
|
||||
|
||||
var watcher = FileWatcher.new("./src")
|
||||
|
||||
watcher.start { |event|
|
||||
System.print("[%(event.filename)]")
|
||||
if (event.isRename) {
|
||||
System.print(" Created/Deleted/Renamed")
|
||||
}
|
||||
if (event.isChange) {
|
||||
System.print(" Modified")
|
||||
}
|
||||
}
|
||||
|
||||
System.print("Watching ./src directory...")
|
||||
System.print("Press Ctrl+C to stop")</code></pre>
|
||||
|
||||
<h3>Auto-Reload Configuration</h3>
|
||||
<pre><code>import "fswatch" for FileWatcher
|
||||
import "io" for File
|
||||
import "json" for Json
|
||||
|
||||
var config = {}
|
||||
|
||||
var loadConfig = Fn.new {
|
||||
var content = File.read("config.json")
|
||||
config = Json.parse(content)
|
||||
System.print("Config loaded: %(config)")
|
||||
}
|
||||
|
||||
loadConfig.call()
|
||||
|
||||
var watcher = FileWatcher.new("./config.json")
|
||||
watcher.start { |event|
|
||||
System.print("Config file changed, reloading...")
|
||||
loadConfig.call()
|
||||
}
|
||||
|
||||
System.print("Running with auto-reload...")</code></pre>
|
||||
|
||||
<h3>Build on Change</h3>
|
||||
<pre><code>import "fswatch" for FileWatcher
|
||||
import "subprocess" for Subprocess
|
||||
|
||||
var watcher = FileWatcher.new("./src")
|
||||
|
||||
var build = Fn.new {
|
||||
System.print("Building...")
|
||||
var result = Subprocess.run("make", ["build"])
|
||||
if (result.exitCode == 0) {
|
||||
System.print("Build successful!")
|
||||
} else {
|
||||
System.print("Build failed!")
|
||||
System.print(result.stderr)
|
||||
}
|
||||
}
|
||||
|
||||
watcher.start { |event|
|
||||
if (event.filename.endsWith(".c") || event.filename.endsWith(".h")) {
|
||||
System.print("%(event.filename) changed")
|
||||
build.call()
|
||||
}
|
||||
}
|
||||
|
||||
System.print("Watching for source changes...")</code></pre>
|
||||
|
||||
<h3>Multiple Watchers</h3>
|
||||
<pre><code>import "fswatch" for FileWatcher
|
||||
|
||||
var srcWatcher = FileWatcher.new("./src")
|
||||
var testWatcher = FileWatcher.new("./test")
|
||||
|
||||
srcWatcher.start { |event|
|
||||
System.print("[SRC] %(event.filename)")
|
||||
}
|
||||
|
||||
testWatcher.start { |event|
|
||||
System.print("[TEST] %(event.filename)")
|
||||
}
|
||||
|
||||
System.print("Watching src/ and test/ directories...")</code></pre>
|
||||
|
||||
<h3>Debounced Watcher</h3>
|
||||
<pre><code>import "fswatch" for FileWatcher
|
||||
import "timer" for Timer
|
||||
import "datetime" for DateTime
|
||||
|
||||
var lastChange = null
|
||||
var debounceMs = 500
|
||||
|
||||
var watcher = FileWatcher.new("./src")
|
||||
|
||||
watcher.start { |event|
|
||||
var now = DateTime.now()
|
||||
if (lastChange == null || (now - lastChange).milliseconds > debounceMs) {
|
||||
lastChange = now
|
||||
System.print("Change detected: %(event.filename)")
|
||||
}
|
||||
}
|
||||
|
||||
System.print("Watching with %(debounceMs)ms debounce...")</code></pre>
|
||||
|
||||
<h3>Graceful Shutdown</h3>
|
||||
<pre><code>import "fswatch" for FileWatcher
|
||||
import "signal" for Signal
|
||||
|
||||
var watcher = FileWatcher.new("./data")
|
||||
|
||||
watcher.start { |event|
|
||||
System.print("%(event.filename) changed")
|
||||
}
|
||||
|
||||
Signal.trap(Signal.SIGINT) {
|
||||
System.print("\nStopping watcher...")
|
||||
watcher.stop()
|
||||
System.print("Watcher stopped: %(watcher.isActive)")
|
||||
}
|
||||
|
||||
System.print("Watching ./data (Ctrl+C to stop)")</code></pre>
|
||||
|
||||
<div class="admonition note">
|
||||
<div class="admonition-title">Note</div>
|
||||
<p>File system event behavior varies by operating system. On some platforms, multiple events may be delivered for a single change, or event types may overlap (both <code>isRename</code> and <code>isChange</code> true).</p>
|
||||
</div>
|
||||
|
||||
<div class="admonition tip">
|
||||
<div class="admonition-title">Tip</div>
|
||||
<p>When watching directories, the <code>filename</code> property contains the relative path of the changed file within the watched directory, not the full path.</p>
|
||||
</div>
|
||||
|
||||
<div class="admonition warning">
|
||||
<div class="admonition-title">Warning</div>
|
||||
<p>Watching a large directory tree may consume significant system resources. Consider watching specific subdirectories when possible.</p>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="env.html" class="prev">env</a>
|
||||
<a href="html.html" class="next">html</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
<script src="../js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -42,46 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="html.html" class="active">html</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html" class="active">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@ -274,8 +289,8 @@ for (key in params.keys) {
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="uuid.html" class="prev">uuid</a>
|
||||
<a href="argparse.html" class="next">argparse</a>
|
||||
<a href="fswatch.html" class="prev">fswatch</a>
|
||||
<a href="http.html" class="next">http</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@ -42,27 +42,38 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html" class="active">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html" class="active">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
|
||||
@ -42,34 +42,38 @@
|
||||
<li><a href="index.html" class="active">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
@ -107,7 +111,7 @@
|
||||
<article>
|
||||
<h1>API Reference</h1>
|
||||
|
||||
<p>Wren-CLI provides 29 built-in modules covering networking, file I/O, data processing, system operations, and more. All modules are imported using the <code>import</code> statement.</p>
|
||||
<p>Wren-CLI provides 32 built-in modules covering networking, file I/O, data processing, system operations, and more. All modules are imported using the <code>import</code> statement.</p>
|
||||
|
||||
<pre><code>import "http" for Http
|
||||
import "json" for Json
|
||||
@ -147,6 +151,10 @@ import "io" for File</code></pre>
|
||||
<h3><a href="net.html">net</a></h3>
|
||||
<p>Low-level TCP sockets and servers for custom network protocols.</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3><a href="udp.html">udp</a></h3>
|
||||
<p>UDP datagram sockets for connectionless networking.</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3><a href="dns.html">dns</a></h3>
|
||||
<p>DNS resolution for hostname to IP address lookups.</p>
|
||||
@ -219,6 +227,14 @@ import "io" for File</code></pre>
|
||||
<h3><a href="pathlib.html">pathlib</a></h3>
|
||||
<p>Object-oriented filesystem paths with glob, walk, and tree operations.</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3><a href="sysinfo.html">sysinfo</a></h3>
|
||||
<p>System information: CPU, memory, uptime, and network interfaces.</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3><a href="fswatch.html">fswatch</a></h3>
|
||||
<p>File system watching for monitoring file and directory changes.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Data & Time</h2>
|
||||
@ -296,6 +312,11 @@ import "io" for File</code></pre>
|
||||
<td>Socket, Server</td>
|
||||
<td>TCP networking</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="udp.html">udp</a></td>
|
||||
<td>UdpSocket, UdpMessage</td>
|
||||
<td>UDP networking</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="dns.html">dns</a></td>
|
||||
<td>Dns</td>
|
||||
@ -336,6 +357,11 @@ import "io" for File</code></pre>
|
||||
<td>Env</td>
|
||||
<td>Environment variables</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="fswatch.html">fswatch</a></td>
|
||||
<td>FileWatcher, FsEvent</td>
|
||||
<td>File system watching</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="signal.html">signal</a></td>
|
||||
<td>Signal</td>
|
||||
@ -346,6 +372,11 @@ import "io" for File</code></pre>
|
||||
<td>Subprocess</td>
|
||||
<td>External processes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="sysinfo.html">sysinfo</a></td>
|
||||
<td>SysInfo</td>
|
||||
<td>System information</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="sqlite.html">sqlite</a></td>
|
||||
<td>Sqlite</td>
|
||||
@ -358,8 +389,8 @@ import "io" for File</code></pre>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="timer.html">timer</a></td>
|
||||
<td>Timer</td>
|
||||
<td>Timers and delays</td>
|
||||
<td>Timer, TimerHandle</td>
|
||||
<td>Timers, delays, and intervals</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="io.html">io</a></td>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html" class="active">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@ -93,7 +115,7 @@
|
||||
|
||||
<p>The <code>io</code> module provides file and directory operations, as well as stdin/stdout handling.</p>
|
||||
|
||||
<pre><code>import "io" for File, Directory, Stdin, Stdout</code></pre>
|
||||
<pre><code>import "io" for File, Directory, Stdin, Stdout, Stat</code></pre>
|
||||
|
||||
<h2>File Class</h2>
|
||||
|
||||
@ -143,7 +165,13 @@ System.print(content)</code></pre>
|
||||
<div class="method-signature">
|
||||
<span class="method-name">File.rename</span>(<span class="param">oldPath</span>, <span class="param">newPath</span>)
|
||||
</div>
|
||||
<p>Renames or moves a file.</p>
|
||||
<p>Renames a file within the same filesystem.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">File.move</span>(<span class="param">source</span>, <span class="param">dest</span>)
|
||||
</div>
|
||||
<p>Moves a file from source to destination. Uses libuv's async rename operation.</p>
|
||||
<pre><code>File.move("old/location/file.txt", "new/location/file.txt")</code></pre>
|
||||
|
||||
<h2>Directory Class</h2>
|
||||
|
||||
@ -214,6 +242,96 @@ System.print("Hello, %(name)!")</code></pre>
|
||||
</div>
|
||||
<p>Flushes the stdout buffer.</p>
|
||||
|
||||
<h2>Stat Class</h2>
|
||||
|
||||
<div class="class-header">
|
||||
<h3>Stat</h3>
|
||||
<p>File metadata and statistics</p>
|
||||
</div>
|
||||
|
||||
<h3>Static Methods</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">Stat.path</span>(<span class="param">path</span>) → <span class="type">Stat</span>
|
||||
</div>
|
||||
<p>Returns a Stat object for the specified path.</p>
|
||||
<pre><code>var stat = Stat.path("/etc/hosts")
|
||||
System.print("Size: %(stat.size) bytes")</code></pre>
|
||||
|
||||
<h3>Properties</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">size</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The size of the file in bytes.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">isFile</span> → <span class="type">Bool</span>
|
||||
</div>
|
||||
<p>True if the path is a regular file.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">isDirectory</span> → <span class="type">Bool</span>
|
||||
</div>
|
||||
<p>True if the path is a directory.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">mtime</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The modification time as a Unix timestamp (seconds since epoch).</p>
|
||||
<pre><code>var stat = Stat.path("file.txt")
|
||||
System.print("Modified: %(stat.mtime)")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">atime</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The access time as a Unix timestamp.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">ctime</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The change time (inode change) as a Unix timestamp.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">mode</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The file permission mode.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">inode</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The inode number.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">device</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The device ID containing the file.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">linkCount</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The number of hard links to the file.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">user</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The user ID of the file owner.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">group</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The group ID of the file.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">blockSize</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The preferred block size for I/O operations.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">blockCount</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The number of blocks allocated for the file.</p>
|
||||
|
||||
<h2>Examples</h2>
|
||||
|
||||
<h3>Reading and Writing Files</h3>
|
||||
|
||||
@ -42,27 +42,38 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html" class="active">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html" class="active">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html" class="active">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html" class="active">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,46 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html" class="active">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html" class="active">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html" class="active">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html" class="active">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html" class="active">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html" class="active">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html" class="active">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,34 +42,38 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html" class="active">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html" class="active">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
@ -425,6 +429,30 @@ System.print(published) // article.txt</code></pre>
|
||||
<p>Copies this file to <code>dest</code>.</p>
|
||||
<pre><code>Path.new("original.txt").copyfile("backup.txt")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">size</span>() → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the size of the file in bytes.</p>
|
||||
<pre><code>var bytes = Path.new("data.txt").size()
|
||||
System.print("File size: %(bytes) bytes")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">mtime</span>() → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the modification time as a Unix timestamp (seconds since epoch).</p>
|
||||
<pre><code>var modified = Path.new("file.txt").mtime()
|
||||
System.print("Last modified: %(modified)")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">atime</span>() → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the access time as a Unix timestamp.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">ctime</span>() → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the change time (inode change) as a Unix timestamp.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">chmod</span>(<span class="param">mode</span>)
|
||||
</div>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html" class="active">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html" class="active">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html" class="active">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html" class="active">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html" class="active">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html" class="active">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@ -342,8 +364,8 @@ while (true) {
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="env.html" class="prev">env</a>
|
||||
<a href="subprocess.html" class="next">subprocess</a>
|
||||
<a href="scheduler.html" class="prev">scheduler</a>
|
||||
<a href="sqlite.html" class="next">sqlite</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html" class="active">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html" class="active">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@ -249,8 +271,8 @@ db.close()</code></pre>
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="subprocess.html" class="prev">subprocess</a>
|
||||
<a href="datetime.html" class="next">datetime</a>
|
||||
<a href="signal.html" class="prev">signal</a>
|
||||
<a href="subprocess.html" class="next">subprocess</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@ -41,34 +41,39 @@
|
||||
<ul>
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html" class="active">String</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html" class="active">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html" class="active">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@ -172,8 +194,8 @@ System.print("Lines: %(result["stdout"].trim())")</code></pre>
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="signal.html" class="prev">signal</a>
|
||||
<a href="sqlite.html" class="next">sqlite</a>
|
||||
<a href="sqlite.html" class="prev">sqlite</a>
|
||||
<a href="sysinfo.html" class="next">sysinfo</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
358
manual/api/sysinfo.html
Normal file
358
manual/api/sysinfo.html
Normal file
@ -0,0 +1,358 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- retoor <retoor@molodetz.nl> -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>sysinfo - Wren-CLI Manual</title>
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<button class="mobile-menu-toggle">Menu</button>
|
||||
<div class="container">
|
||||
<aside class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h1><a href="../index.html">Wren-CLI</a></h1>
|
||||
<div class="version">v0.4.0</div>
|
||||
</div>
|
||||
<nav class="sidebar-nav">
|
||||
<div class="section">
|
||||
<span class="section-title">Getting Started</span>
|
||||
<ul>
|
||||
<li><a href="../getting-started/index.html">Overview</a></li>
|
||||
<li><a href="../getting-started/installation.html">Installation</a></li>
|
||||
<li><a href="../getting-started/first-script.html">First Script</a></li>
|
||||
<li><a href="../getting-started/repl.html">Using the REPL</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Language</span>
|
||||
<ul>
|
||||
<li><a href="../language/index.html">Syntax Overview</a></li>
|
||||
<li><a href="../language/classes.html">Classes</a></li>
|
||||
<li><a href="../language/methods.html">Methods</a></li>
|
||||
<li><a href="../language/control-flow.html">Control Flow</a></li>
|
||||
<li><a href="../language/fibers.html">Fibers</a></li>
|
||||
<li><a href="../language/modules.html">Modules</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">API Reference</span>
|
||||
<ul>
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html" class="active">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
</aside>
|
||||
<main class="content">
|
||||
<nav class="breadcrumb">
|
||||
<a href="../index.html">Home</a>
|
||||
<span class="separator">/</span>
|
||||
<a href="index.html">API Reference</a>
|
||||
<span class="separator">/</span>
|
||||
<span>sysinfo</span>
|
||||
</nav>
|
||||
|
||||
<article>
|
||||
<h1>sysinfo</h1>
|
||||
|
||||
<p>The <code>sysinfo</code> module provides system information including CPU details, memory usage, uptime, and network interfaces. All values are retrieved from libuv.</p>
|
||||
|
||||
<pre><code>import "sysinfo" for SysInfo</code></pre>
|
||||
|
||||
<div class="toc">
|
||||
<h4>On This Page</h4>
|
||||
<ul>
|
||||
<li><a href="#sysinfo-class">SysInfo Class</a></li>
|
||||
<li><a href="#examples">Examples</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<h2 id="sysinfo-class">SysInfo Class</h2>
|
||||
|
||||
<div class="class-header">
|
||||
<h3>SysInfo</h3>
|
||||
<p>System information properties</p>
|
||||
</div>
|
||||
|
||||
<h3>Static Properties</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.cpuInfo</span> → <span class="type">List</span>
|
||||
</div>
|
||||
<p>Returns a list of maps containing CPU information. Each map includes <code>model</code>, <code>speed</code>, and <code>times</code> (with <code>user</code>, <code>nice</code>, <code>sys</code>, <code>idle</code>, <code>irq</code>).</p>
|
||||
<pre><code>var cpus = SysInfo.cpuInfo
|
||||
for (cpu in cpus) {
|
||||
System.print("Model: %(cpu["model"])")
|
||||
System.print("Speed: %(cpu["speed"]) MHz")
|
||||
}</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.cpuCount</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the number of CPUs/cores available on the system.</p>
|
||||
<pre><code>System.print("CPU count: %(SysInfo.cpuCount)")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.loadAverage</span> → <span class="type">List</span>
|
||||
</div>
|
||||
<p>Returns the system load averages as a list of three numbers: 1-minute, 5-minute, and 15-minute averages. On Windows, returns <code>[0, 0, 0]</code>.</p>
|
||||
<pre><code>var load = SysInfo.loadAverage
|
||||
System.print("Load: %(load[0]) %(load[1]) %(load[2])")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.totalMemory</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the total system memory in bytes.</p>
|
||||
<pre><code>var totalMB = SysInfo.totalMemory / 1024 / 1024
|
||||
System.print("Total memory: %(totalMB) MB")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.freeMemory</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the free system memory in bytes.</p>
|
||||
<pre><code>var freeMB = SysInfo.freeMemory / 1024 / 1024
|
||||
System.print("Free memory: %(freeMB) MB")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.uptime</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the system uptime in seconds.</p>
|
||||
<pre><code>var hours = (SysInfo.uptime / 3600).floor
|
||||
System.print("Uptime: %(hours) hours")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.hostname</span> → <span class="type">String</span>
|
||||
</div>
|
||||
<p>Returns the system hostname.</p>
|
||||
<pre><code>System.print("Hostname: %(SysInfo.hostname)")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.networkInterfaces</span> → <span class="type">Map</span>
|
||||
</div>
|
||||
<p>Returns a map of network interfaces. Each key is an interface name, and each value is a list of address maps containing <code>address</code>, <code>netmask</code>, <code>family</code> (IPv4 or IPv6), <code>internal</code>, and <code>mac</code>.</p>
|
||||
<pre><code>var interfaces = SysInfo.networkInterfaces
|
||||
for (name in interfaces.keys) {
|
||||
System.print("Interface: %(name)")
|
||||
for (addr in interfaces[name]) {
|
||||
System.print(" %(addr["family"]): %(addr["address"])")
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.hrtime</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns a high-resolution time value in nanoseconds. Useful for precise timing measurements.</p>
|
||||
<pre><code>var start = SysInfo.hrtime
|
||||
// ... do some work ...
|
||||
var elapsed = SysInfo.hrtime - start
|
||||
System.print("Elapsed: %(elapsed / 1000000) ms")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.residentMemory</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the resident set size (RSS) of the current process in bytes.</p>
|
||||
<pre><code>var rssMB = SysInfo.residentMemory / 1024 / 1024
|
||||
System.print("Process RSS: %(rssMB) MB")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">SysInfo.constrainedMemory</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the memory limit for the process in bytes (e.g., cgroup limit). Returns 0 if no limit is set.</p>
|
||||
<pre><code>var limit = SysInfo.constrainedMemory
|
||||
if (limit > 0) {
|
||||
System.print("Memory limit: %(limit / 1024 / 1024) MB")
|
||||
} else {
|
||||
System.print("No memory limit set")
|
||||
}</code></pre>
|
||||
|
||||
<h2 id="examples">Examples</h2>
|
||||
|
||||
<h3>System Overview</h3>
|
||||
<pre><code>import "sysinfo" for SysInfo
|
||||
|
||||
System.print("=== System Information ===")
|
||||
System.print("Hostname: %(SysInfo.hostname)")
|
||||
System.print("CPUs: %(SysInfo.cpuCount)")
|
||||
System.print("")
|
||||
|
||||
System.print("=== Memory ===")
|
||||
var totalGB = (SysInfo.totalMemory / 1024 / 1024 / 1024 * 100).floor / 100
|
||||
var freeGB = (SysInfo.freeMemory / 1024 / 1024 / 1024 * 100).floor / 100
|
||||
var usedPercent = ((1 - SysInfo.freeMemory / SysInfo.totalMemory) * 100).floor
|
||||
System.print("Total: %(totalGB) GB")
|
||||
System.print("Free: %(freeGB) GB")
|
||||
System.print("Used: %(usedPercent)\%")
|
||||
System.print("")
|
||||
|
||||
System.print("=== Load Average ===")
|
||||
var load = SysInfo.loadAverage
|
||||
System.print("1 min: %(load[0])")
|
||||
System.print("5 min: %(load[1])")
|
||||
System.print("15 min: %(load[2])")
|
||||
System.print("")
|
||||
|
||||
System.print("=== Uptime ===")
|
||||
var uptime = SysInfo.uptime
|
||||
var days = (uptime / 86400).floor
|
||||
var hours = ((uptime % 86400) / 3600).floor
|
||||
var minutes = ((uptime % 3600) / 60).floor
|
||||
System.print("%(days) days, %(hours) hours, %(minutes) minutes")</code></pre>
|
||||
|
||||
<h3>CPU Information</h3>
|
||||
<pre><code>import "sysinfo" for SysInfo
|
||||
|
||||
var cpus = SysInfo.cpuInfo
|
||||
System.print("CPU Information:")
|
||||
System.print("================")
|
||||
|
||||
var i = 0
|
||||
for (cpu in cpus) {
|
||||
System.print("CPU %(i): %(cpu["model"])")
|
||||
System.print(" Speed: %(cpu["speed"]) MHz")
|
||||
var times = cpu["times"]
|
||||
var total = times["user"] + times["nice"] + times["sys"] + times["idle"] + times["irq"]
|
||||
var idle = (times["idle"] / total * 100).floor
|
||||
System.print(" Idle: %(idle)\%")
|
||||
i = i + 1
|
||||
}</code></pre>
|
||||
|
||||
<h3>Network Interfaces</h3>
|
||||
<pre><code>import "sysinfo" for SysInfo
|
||||
|
||||
var interfaces = SysInfo.networkInterfaces
|
||||
|
||||
System.print("Network Interfaces:")
|
||||
System.print("===================")
|
||||
|
||||
for (name in interfaces.keys) {
|
||||
var addrs = interfaces[name]
|
||||
System.print("%(name):")
|
||||
for (addr in addrs) {
|
||||
if (!addr["internal"]) {
|
||||
System.print(" %(addr["family"]): %(addr["address"])")
|
||||
if (addr["mac"] != "00:00:00:00:00:00") {
|
||||
System.print(" MAC: %(addr["mac"])")
|
||||
}
|
||||
}
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<h3>Performance Timing</h3>
|
||||
<pre><code>import "sysinfo" for SysInfo
|
||||
|
||||
var measure = Fn.new { |name, fn|
|
||||
var start = SysInfo.hrtime
|
||||
fn.call()
|
||||
var elapsed = SysInfo.hrtime - start
|
||||
System.print("%(name): %(elapsed / 1000000) ms")
|
||||
}
|
||||
|
||||
measure.call("String concatenation") {
|
||||
var s = ""
|
||||
for (i in 0...1000) {
|
||||
s = s + "x"
|
||||
}
|
||||
}
|
||||
|
||||
measure.call("List operations") {
|
||||
var list = []
|
||||
for (i in 0...10000) {
|
||||
list.add(i)
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<h3>Memory Monitoring</h3>
|
||||
<pre><code>import "sysinfo" for SysInfo
|
||||
import "timer" for Timer
|
||||
|
||||
System.print("Memory Monitor (press Ctrl+C to stop)")
|
||||
System.print("=====================================")
|
||||
|
||||
while (true) {
|
||||
var totalMB = (SysInfo.totalMemory / 1024 / 1024).floor
|
||||
var freeMB = (SysInfo.freeMemory / 1024 / 1024).floor
|
||||
var rssMB = (SysInfo.residentMemory / 1024 / 1024).floor
|
||||
var usedPercent = ((1 - SysInfo.freeMemory / SysInfo.totalMemory) * 100).floor
|
||||
|
||||
System.print("System: %(freeMB)/%(totalMB) MB free (%(usedPercent)\% used) | Process RSS: %(rssMB) MB")
|
||||
Timer.sleep(1000)
|
||||
}</code></pre>
|
||||
|
||||
<div class="admonition note">
|
||||
<div class="admonition-title">Note</div>
|
||||
<p>Load average values are not available on Windows and will return <code>[0, 0, 0]</code>.</p>
|
||||
</div>
|
||||
|
||||
<div class="admonition tip">
|
||||
<div class="admonition-title">Tip</div>
|
||||
<p>Use <code>SysInfo.hrtime</code> for precise performance measurements. It provides nanosecond resolution and is not affected by system clock adjustments.</p>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="subprocess.html" class="prev">subprocess</a>
|
||||
<a href="tempfile.html" class="next">tempfile</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
<script src="../js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -42,47 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="tempfile.html" class="active">tempfile</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html" class="active">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@ -360,8 +374,8 @@ System.print("Log file: %(tmp.name)")</code></pre>
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="pathlib.html" class="prev">pathlib</a>
|
||||
<a href="scheduler.html" class="next">scheduler</a>
|
||||
<a href="sysinfo.html" class="prev">sysinfo</a>
|
||||
<a href="timer.html" class="next">timer</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html" class="active">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html" class="active">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@ -91,9 +113,9 @@
|
||||
<article>
|
||||
<h1>timer</h1>
|
||||
|
||||
<p>The <code>timer</code> module provides timing functionality for delays and intervals.</p>
|
||||
<p>The <code>timer</code> module provides timing functionality for delays, intervals, and immediate execution.</p>
|
||||
|
||||
<pre><code>import "timer" for Timer</code></pre>
|
||||
<pre><code>import "timer" for Timer, TimerHandle</code></pre>
|
||||
|
||||
<h2>Timer Class</h2>
|
||||
|
||||
@ -115,6 +137,63 @@
|
||||
Timer.sleep(1000) // Wait 1 second
|
||||
System.print("Done!")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">Timer.interval</span>(<span class="param">milliseconds</span>, <span class="param">fn</span>) → <span class="type">TimerHandle</span>
|
||||
</div>
|
||||
<p>Creates a repeating timer that calls the callback function at the specified interval. Returns a TimerHandle that can be used to stop the interval.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">milliseconds</span> <span class="param-type">(Num)</span> - Interval between calls in milliseconds</li>
|
||||
<li><span class="param-name">fn</span> <span class="param-type">(Fn)</span> - Callback function to execute (no arguments)</li>
|
||||
<li><span class="returns">Returns:</span> TimerHandle for controlling the interval</li>
|
||||
</ul>
|
||||
<pre><code>var count = 0
|
||||
var handle = Timer.interval(1000) {
|
||||
count = count + 1
|
||||
System.print("Tick %(count)")
|
||||
if (count >= 5) {
|
||||
handle.stop()
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">Timer.immediate</span>(<span class="param">fn</span>)
|
||||
</div>
|
||||
<p>Schedules a function to run on the next iteration of the event loop. Useful for deferring execution without blocking.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">fn</span> <span class="param-type">(Fn)</span> - Callback function to execute (no arguments)</li>
|
||||
</ul>
|
||||
<pre><code>System.print("Before")
|
||||
Timer.immediate {
|
||||
System.print("Deferred execution")
|
||||
}
|
||||
System.print("After")
|
||||
// Output: Before, After, Deferred execution</code></pre>
|
||||
|
||||
<h2>TimerHandle Class</h2>
|
||||
|
||||
<div class="class-header">
|
||||
<h3>TimerHandle</h3>
|
||||
<p>Handle for controlling interval timers</p>
|
||||
</div>
|
||||
|
||||
<h3>Methods</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">stop</span>()
|
||||
</div>
|
||||
<p>Stops the interval timer. After calling stop, the callback will no longer be invoked.</p>
|
||||
<pre><code>handle.stop()</code></pre>
|
||||
|
||||
<h3>Properties</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">isActive</span> → <span class="type">Bool</span>
|
||||
</div>
|
||||
<p>Returns true if the interval timer is still active.</p>
|
||||
<pre><code>if (handle.isActive) {
|
||||
System.print("Timer is running")
|
||||
}</code></pre>
|
||||
|
||||
<h2>Examples</h2>
|
||||
|
||||
<h3>Basic Delay</h3>
|
||||
@ -187,15 +266,73 @@ for (step in 1..20) {
|
||||
}
|
||||
System.print("\rDone! ")</code></pre>
|
||||
|
||||
<h3>Interval Timer</h3>
|
||||
<pre><code>import "timer" for Timer, TimerHandle
|
||||
|
||||
var seconds = 0
|
||||
var handle = Timer.interval(1000) {
|
||||
seconds = seconds + 1
|
||||
System.print("Elapsed: %(seconds) seconds")
|
||||
}
|
||||
|
||||
Timer.sleep(5000)
|
||||
handle.stop()
|
||||
System.print("Timer stopped")</code></pre>
|
||||
|
||||
<h3>Periodic Status Updates</h3>
|
||||
<pre><code>import "timer" for Timer, TimerHandle
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var handle = Timer.interval(2000) {
|
||||
var freeMB = (SysInfo.freeMemory / 1024 / 1024).floor
|
||||
var load = SysInfo.loadAverage[0]
|
||||
System.print("Memory: %(freeMB) MB free | Load: %(load)")
|
||||
}
|
||||
|
||||
System.print("Monitoring system (runs for 10 seconds)...")
|
||||
Timer.sleep(10000)
|
||||
handle.stop()</code></pre>
|
||||
|
||||
<h3>Immediate Execution</h3>
|
||||
<pre><code>import "timer" for Timer
|
||||
|
||||
System.print("1. Synchronous")
|
||||
|
||||
Timer.immediate {
|
||||
System.print("3. Immediate callback")
|
||||
}
|
||||
|
||||
System.print("2. Still synchronous")
|
||||
|
||||
Timer.sleep(100)</code></pre>
|
||||
|
||||
<h3>Self-Stopping Interval</h3>
|
||||
<pre><code>import "timer" for Timer, TimerHandle
|
||||
|
||||
var count = 0
|
||||
var handle = Timer.interval(500) {
|
||||
count = count + 1
|
||||
System.print("Count: %(count)")
|
||||
if (count >= 10) {
|
||||
System.print("Stopping at %(count)")
|
||||
handle.stop()
|
||||
}
|
||||
}</code></pre>
|
||||
|
||||
<div class="admonition note">
|
||||
<div class="admonition-title">Note</div>
|
||||
<p>Timer.sleep is non-blocking at the event loop level. The current fiber suspends, but other scheduled operations can continue.</p>
|
||||
</div>
|
||||
|
||||
<div class="admonition tip">
|
||||
<div class="admonition-title">Tip</div>
|
||||
<p>Use <code>Timer.interval</code> for recurring tasks like heartbeats, polling, or animations. The returned handle allows you to stop the interval from within the callback itself.</p>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="datetime.html" class="prev">datetime</a>
|
||||
<a href="io.html" class="next">io</a>
|
||||
<a href="tempfile.html" class="prev">tempfile</a>
|
||||
<a href="tls.html" class="next">tls</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@ -42,39 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html" class="active">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html" class="active">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@ -235,8 +257,8 @@ socket.close()</code></pre>
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="websocket.html" class="prev">websocket</a>
|
||||
<a href="net.html" class="next">net</a>
|
||||
<a href="timer.html" class="prev">timer</a>
|
||||
<a href="udp.html" class="next">udp</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
432
manual/api/udp.html
Normal file
432
manual/api/udp.html
Normal file
@ -0,0 +1,432 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- retoor <retoor@molodetz.nl> -->
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>udp - Wren-CLI Manual</title>
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<button class="mobile-menu-toggle">Menu</button>
|
||||
<div class="container">
|
||||
<aside class="sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h1><a href="../index.html">Wren-CLI</a></h1>
|
||||
<div class="version">v0.4.0</div>
|
||||
</div>
|
||||
<nav class="sidebar-nav">
|
||||
<div class="section">
|
||||
<span class="section-title">Getting Started</span>
|
||||
<ul>
|
||||
<li><a href="../getting-started/index.html">Overview</a></li>
|
||||
<li><a href="../getting-started/installation.html">Installation</a></li>
|
||||
<li><a href="../getting-started/first-script.html">First Script</a></li>
|
||||
<li><a href="../getting-started/repl.html">Using the REPL</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Language</span>
|
||||
<ul>
|
||||
<li><a href="../language/index.html">Syntax Overview</a></li>
|
||||
<li><a href="../language/classes.html">Classes</a></li>
|
||||
<li><a href="../language/methods.html">Methods</a></li>
|
||||
<li><a href="../language/control-flow.html">Control Flow</a></li>
|
||||
<li><a href="../language/fibers.html">Fibers</a></li>
|
||||
<li><a href="../language/modules.html">Modules</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">API Reference</span>
|
||||
<ul>
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html" class="active">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
</aside>
|
||||
<main class="content">
|
||||
<nav class="breadcrumb">
|
||||
<a href="../index.html">Home</a>
|
||||
<span class="separator">/</span>
|
||||
<a href="index.html">API Reference</a>
|
||||
<span class="separator">/</span>
|
||||
<span>udp</span>
|
||||
</nav>
|
||||
|
||||
<article>
|
||||
<h1>udp</h1>
|
||||
|
||||
<p>The <code>udp</code> module provides UDP (User Datagram Protocol) socket functionality for connectionless networking. UDP is useful for applications requiring fast, lightweight communication without the overhead of TCP connection management.</p>
|
||||
|
||||
<pre><code>import "udp" for UdpSocket, UdpMessage</code></pre>
|
||||
|
||||
<div class="toc">
|
||||
<h4>On This Page</h4>
|
||||
<ul>
|
||||
<li><a href="#udpsocket-class">UdpSocket Class</a></li>
|
||||
<li><a href="#udpmessage-class">UdpMessage Class</a></li>
|
||||
<li><a href="#examples">Examples</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<h2 id="udpsocket-class">UdpSocket Class</h2>
|
||||
|
||||
<div class="class-header">
|
||||
<h3>UdpSocket</h3>
|
||||
<p>UDP datagram socket for sending and receiving messages</p>
|
||||
</div>
|
||||
|
||||
<h3>Constructor</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">UdpSocket.new</span>() → <span class="type">UdpSocket</span>
|
||||
</div>
|
||||
<p>Creates a new UDP socket.</p>
|
||||
<pre><code>var socket = UdpSocket.new()</code></pre>
|
||||
|
||||
<h3>Methods</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">bind</span>(<span class="param">host</span>, <span class="param">port</span>)
|
||||
</div>
|
||||
<p>Binds the socket to a local address and port. Required before receiving messages.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">host</span> <span class="param-type">(String)</span> - Local address to bind (e.g., "0.0.0.0" for all interfaces)</li>
|
||||
<li><span class="param-name">port</span> <span class="param-type">(Num)</span> - Port number to bind</li>
|
||||
</ul>
|
||||
<pre><code>socket.bind("0.0.0.0", 8080)</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">send</span>(<span class="param">data</span>, <span class="param">host</span>, <span class="param">port</span>)
|
||||
</div>
|
||||
<p>Sends a datagram to the specified address. Async operation.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">data</span> <span class="param-type">(String)</span> - Data to send</li>
|
||||
<li><span class="param-name">host</span> <span class="param-type">(String)</span> - Destination hostname or IP</li>
|
||||
<li><span class="param-name">port</span> <span class="param-type">(Num)</span> - Destination port</li>
|
||||
</ul>
|
||||
<pre><code>socket.send("Hello!", "192.168.1.100", 8080)</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">receive</span>() → <span class="type">UdpMessage</span>
|
||||
</div>
|
||||
<p>Receives a datagram. Blocks until data arrives. Returns a UdpMessage containing the data and sender information.</p>
|
||||
<pre><code>var msg = socket.receive()
|
||||
System.print("From %(msg.address):%(msg.port): %(msg.data)")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">close</span>()
|
||||
</div>
|
||||
<p>Closes the socket.</p>
|
||||
<pre><code>socket.close()</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">setBroadcast</span>(<span class="param">enabled</span>)
|
||||
</div>
|
||||
<p>Enables or disables broadcast mode. When enabled, the socket can send to broadcast addresses.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">enabled</span> <span class="param-type">(Bool)</span> - True to enable broadcast</li>
|
||||
</ul>
|
||||
<pre><code>socket.setBroadcast(true)
|
||||
socket.send("Broadcast message", "255.255.255.255", 8080)</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">setMulticastTTL</span>(<span class="param">ttl</span>)
|
||||
</div>
|
||||
<p>Sets the time-to-live for multicast packets.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">ttl</span> <span class="param-type">(Num)</span> - TTL value (1-255)</li>
|
||||
</ul>
|
||||
<pre><code>socket.setMulticastTTL(64)</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">setMulticastLoopback</span>(<span class="param">enabled</span>)
|
||||
</div>
|
||||
<p>Enables or disables multicast loopback. When enabled, the socket receives its own multicast messages.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">enabled</span> <span class="param-type">(Bool)</span> - True to enable loopback</li>
|
||||
</ul>
|
||||
<pre><code>socket.setMulticastLoopback(false)</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">joinMulticast</span>(<span class="param">group</span>)
|
||||
</div>
|
||||
<p>Joins a multicast group on the default interface.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">group</span> <span class="param-type">(String)</span> - Multicast group address (e.g., "239.255.0.1")</li>
|
||||
</ul>
|
||||
<pre><code>socket.joinMulticast("239.255.0.1")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">joinMulticast</span>(<span class="param">group</span>, <span class="param">iface</span>)
|
||||
</div>
|
||||
<p>Joins a multicast group on a specific interface.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">group</span> <span class="param-type">(String)</span> - Multicast group address</li>
|
||||
<li><span class="param-name">iface</span> <span class="param-type">(String)</span> - Local interface address to join from</li>
|
||||
</ul>
|
||||
<pre><code>socket.joinMulticast("239.255.0.1", "192.168.1.100")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">leaveMulticast</span>(<span class="param">group</span>)
|
||||
</div>
|
||||
<p>Leaves a multicast group on the default interface.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">group</span> <span class="param-type">(String)</span> - Multicast group address</li>
|
||||
</ul>
|
||||
<pre><code>socket.leaveMulticast("239.255.0.1")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">leaveMulticast</span>(<span class="param">group</span>, <span class="param">iface</span>)
|
||||
</div>
|
||||
<p>Leaves a multicast group on a specific interface.</p>
|
||||
<ul class="param-list">
|
||||
<li><span class="param-name">group</span> <span class="param-type">(String)</span> - Multicast group address</li>
|
||||
<li><span class="param-name">iface</span> <span class="param-type">(String)</span> - Local interface address</li>
|
||||
</ul>
|
||||
<pre><code>socket.leaveMulticast("239.255.0.1", "192.168.1.100")</code></pre>
|
||||
|
||||
<h3>Properties</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">localAddress</span> → <span class="type">String</span>
|
||||
</div>
|
||||
<p>Returns the local address the socket is bound to.</p>
|
||||
<pre><code>System.print("Bound to: %(socket.localAddress)")</code></pre>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">localPort</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>Returns the local port the socket is bound to.</p>
|
||||
<pre><code>System.print("Port: %(socket.localPort)")</code></pre>
|
||||
|
||||
<h2 id="udpmessage-class">UdpMessage Class</h2>
|
||||
|
||||
<div class="class-header">
|
||||
<h3>UdpMessage</h3>
|
||||
<p>Represents a received UDP datagram</p>
|
||||
</div>
|
||||
|
||||
<h3>Properties</h3>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">data</span> → <span class="type">String</span>
|
||||
</div>
|
||||
<p>The data contained in the message.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">address</span> → <span class="type">String</span>
|
||||
</div>
|
||||
<p>The IP address of the sender.</p>
|
||||
|
||||
<div class="method-signature">
|
||||
<span class="method-name">port</span> → <span class="type">Num</span>
|
||||
</div>
|
||||
<p>The port number of the sender.</p>
|
||||
|
||||
<pre><code>var msg = socket.receive()
|
||||
System.print("Data: %(msg.data)")
|
||||
System.print("From: %(msg.address):%(msg.port)")</code></pre>
|
||||
|
||||
<h2 id="examples">Examples</h2>
|
||||
|
||||
<h3>Simple UDP Server</h3>
|
||||
<pre><code>import "udp" for UdpSocket
|
||||
|
||||
var socket = UdpSocket.new()
|
||||
socket.bind("0.0.0.0", 8080)
|
||||
|
||||
System.print("UDP server listening on port 8080")
|
||||
|
||||
while (true) {
|
||||
var msg = socket.receive()
|
||||
System.print("Received from %(msg.address):%(msg.port): %(msg.data)")
|
||||
|
||||
socket.send("Echo: %(msg.data)", msg.address, msg.port)
|
||||
}</code></pre>
|
||||
|
||||
<h3>Simple UDP Client</h3>
|
||||
<pre><code>import "udp" for UdpSocket
|
||||
|
||||
var socket = UdpSocket.new()
|
||||
socket.bind("0.0.0.0", 0)
|
||||
|
||||
socket.send("Hello, server!", "127.0.0.1", 8080)
|
||||
|
||||
var response = socket.receive()
|
||||
System.print("Server responded: %(response.data)")
|
||||
|
||||
socket.close()</code></pre>
|
||||
|
||||
<h3>Broadcast Discovery</h3>
|
||||
<pre><code>import "udp" for UdpSocket
|
||||
import "timer" for Timer
|
||||
|
||||
var socket = UdpSocket.new()
|
||||
socket.bind("0.0.0.0", 0)
|
||||
socket.setBroadcast(true)
|
||||
|
||||
System.print("Sending discovery broadcast...")
|
||||
socket.send("DISCOVER", "255.255.255.255", 9999)
|
||||
|
||||
System.print("Waiting for responses...")
|
||||
|
||||
var timeout = false
|
||||
var timeoutFiber = Fiber.new {
|
||||
Timer.sleep(3000)
|
||||
timeout = true
|
||||
}
|
||||
timeoutFiber.call()
|
||||
|
||||
while (!timeout) {
|
||||
var msg = socket.receive()
|
||||
System.print("Found device at %(msg.address): %(msg.data)")
|
||||
}
|
||||
|
||||
socket.close()</code></pre>
|
||||
|
||||
<h3>Multicast Group</h3>
|
||||
<pre><code>import "udp" for UdpSocket
|
||||
|
||||
var MULTICAST_GROUP = "239.255.0.1"
|
||||
var MULTICAST_PORT = 5000
|
||||
|
||||
var socket = UdpSocket.new()
|
||||
socket.bind("0.0.0.0", MULTICAST_PORT)
|
||||
socket.joinMulticast(MULTICAST_GROUP)
|
||||
socket.setMulticastLoopback(true)
|
||||
|
||||
System.print("Joined multicast group %(MULTICAST_GROUP)")
|
||||
|
||||
socket.send("Hello multicast!", MULTICAST_GROUP, MULTICAST_PORT)
|
||||
|
||||
var msg = socket.receive()
|
||||
System.print("Received: %(msg.data) from %(msg.address)")
|
||||
|
||||
socket.leaveMulticast(MULTICAST_GROUP)
|
||||
socket.close()</code></pre>
|
||||
|
||||
<h3>DNS-Style Query/Response</h3>
|
||||
<pre><code>import "udp" for UdpSocket
|
||||
import "json" for Json
|
||||
|
||||
var socket = UdpSocket.new()
|
||||
socket.bind("0.0.0.0", 0)
|
||||
|
||||
var query = Json.stringify({
|
||||
"type": "lookup",
|
||||
"name": "example.local"
|
||||
})
|
||||
|
||||
socket.send(query, "192.168.1.1", 5353)
|
||||
|
||||
var response = socket.receive()
|
||||
var result = Json.parse(response.data)
|
||||
System.print("Lookup result: %(result)")
|
||||
|
||||
socket.close()</code></pre>
|
||||
|
||||
<h3>UDP Ping</h3>
|
||||
<pre><code>import "udp" for UdpSocket
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var socket = UdpSocket.new()
|
||||
socket.bind("0.0.0.0", 0)
|
||||
|
||||
var target = "127.0.0.1"
|
||||
var port = 8080
|
||||
|
||||
for (i in 1..5) {
|
||||
var start = SysInfo.hrtime
|
||||
socket.send("PING %(i)", target, port)
|
||||
|
||||
var msg = socket.receive()
|
||||
var elapsed = (SysInfo.hrtime - start) / 1000000
|
||||
|
||||
System.print("Reply from %(msg.address): %(elapsed) ms")
|
||||
}
|
||||
|
||||
socket.close()</code></pre>
|
||||
|
||||
<div class="admonition note">
|
||||
<div class="admonition-title">Note</div>
|
||||
<p>UDP is connectionless and does not guarantee delivery. Messages may be lost, duplicated, or arrive out of order. Use TCP (<code>net</code> module) when reliability is required.</p>
|
||||
</div>
|
||||
|
||||
<div class="admonition tip">
|
||||
<div class="admonition-title">Tip</div>
|
||||
<p>When binding to port 0, the system automatically assigns an available port. Use <code>localPort</code> to retrieve the assigned port number.</p>
|
||||
</div>
|
||||
|
||||
<div class="admonition warning">
|
||||
<div class="admonition-title">Warning</div>
|
||||
<p>Multicast group addresses must be in the range 224.0.0.0 to 239.255.255.255. Using addresses outside this range will cause errors.</p>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="tls.html" class="prev">tls</a>
|
||||
<a href="uuid.html" class="next">uuid</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
<script src="../js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@ -42,46 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html" class="active">uuid</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html" class="active">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
@ -216,8 +231,8 @@ System.print("Created user %(user.name) with ID %(user.id)")</code></pre>
|
||||
</article>
|
||||
|
||||
<footer class="page-footer">
|
||||
<a href="math.html" class="prev">math</a>
|
||||
<a href="html.html" class="next">html</a>
|
||||
<a href="udp.html" class="prev">udp</a>
|
||||
<a href="wdantic.html" class="next">wdantic</a>
|
||||
</footer>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@ -42,46 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="wdantic.html" class="active">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html" class="active">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,46 +42,61 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html" class="active">web</a></li>
|
||||
<li><a href="websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">Tutorials</span>
|
||||
<ul>
|
||||
<li><a href="../tutorials/index.html">Tutorial List</a></li>
|
||||
<li><a href="../tutorials/http-client.html">HTTP Client</a></li>
|
||||
<li><a href="../tutorials/websocket-chat.html">WebSocket Chat</a></li>
|
||||
<li><a href="../tutorials/database-app.html">Database App</a></li>
|
||||
<li><a href="../tutorials/template-rendering.html">Templates</a></li>
|
||||
<li><a href="../tutorials/cli-tool.html">CLI Tool</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<span class="section-title">How-To Guides</span>
|
||||
<ul>
|
||||
<li><a href="../howto/index.html">How-To List</a></li>
|
||||
<li><a href="../howto/http-requests.html">HTTP Requests</a></li>
|
||||
<li><a href="../howto/json-parsing.html">JSON Parsing</a></li>
|
||||
<li><a href="../howto/regex-patterns.html">Regex Patterns</a></li>
|
||||
<li><a href="../howto/file-operations.html">File Operations</a></li>
|
||||
<li><a href="../howto/async-operations.html">Async Operations</a></li>
|
||||
<li><a href="../howto/error-handling.html">Error Handling</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@ -42,27 +42,38 @@
|
||||
<li><a href="index.html">Overview</a></li>
|
||||
<li><a href="string.html">String</a></li>
|
||||
<li><a href="number.html">Num</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="websocket.html" class="active">websocket</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="argparse.html">argparse</a></li>
|
||||
<li><a href="base64.html">base64</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="crypto.html">crypto</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="dataset.html">dataset</a></li>
|
||||
<li><a href="datetime.html">datetime</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="dns.html">dns</a></li>
|
||||
<li><a href="env.html">env</a></li>
|
||||
<li><a href="fswatch.html">fswatch</a></li>
|
||||
<li><a href="html.html">html</a></li>
|
||||
<li><a href="http.html">http</a></li>
|
||||
<li><a href="io.html">io</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="jinja.html">jinja</a></li>
|
||||
<li><a href="json.html">json</a></li>
|
||||
<li><a href="markdown.html">markdown</a></li>
|
||||
<li><a href="math.html">math</a></li>
|
||||
<li><a href="net.html">net</a></li>
|
||||
<li><a href="os.html">os</a></li>
|
||||
<li><a href="pathlib.html">pathlib</a></li>
|
||||
<li><a href="regex.html">regex</a></li>
|
||||
<li><a href="scheduler.html">scheduler</a></li>
|
||||
<li><a href="signal.html">signal</a></li>
|
||||
<li><a href="sqlite.html">sqlite</a></li>
|
||||
<li><a href="subprocess.html">subprocess</a></li>
|
||||
<li><a href="sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="tempfile.html">tempfile</a></li>
|
||||
<li><a href="timer.html">timer</a></li>
|
||||
<li><a href="tls.html">tls</a></li>
|
||||
<li><a href="udp.html">udp</a></li>
|
||||
<li><a href="uuid.html">uuid</a></li>
|
||||
<li><a href="wdantic.html">wdantic</a></li>
|
||||
<li><a href="web.html">web</a></li>
|
||||
<li><a href="websocket.html" class="active">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
|
||||
@ -40,27 +40,40 @@
|
||||
<span class="section-title">API Reference</span>
|
||||
<ul>
|
||||
<li><a href="api/index.html">Overview</a></li>
|
||||
<li><a href="api/http.html">http</a></li>
|
||||
<li><a href="api/websocket.html">websocket</a></li>
|
||||
<li><a href="api/tls.html">tls</a></li>
|
||||
<li><a href="api/net.html">net</a></li>
|
||||
<li><a href="api/dns.html">dns</a></li>
|
||||
<li><a href="api/json.html">json</a></li>
|
||||
<li><a href="api/string.html">String</a></li>
|
||||
<li><a href="api/number.html">Num</a></li>
|
||||
<li><a href="api/argparse.html">argparse</a></li>
|
||||
<li><a href="api/base64.html">base64</a></li>
|
||||
<li><a href="api/regex.html">regex</a></li>
|
||||
<li><a href="api/jinja.html">jinja</a></li>
|
||||
<li><a href="api/crypto.html">crypto</a></li>
|
||||
<li><a href="api/os.html">os</a></li>
|
||||
<li><a href="api/env.html">env</a></li>
|
||||
<li><a href="api/signal.html">signal</a></li>
|
||||
<li><a href="api/subprocess.html">subprocess</a></li>
|
||||
<li><a href="api/sqlite.html">sqlite</a></li>
|
||||
<li><a href="api/dataset.html">dataset</a></li>
|
||||
<li><a href="api/datetime.html">datetime</a></li>
|
||||
<li><a href="api/timer.html">timer</a></li>
|
||||
<li><a href="api/dns.html">dns</a></li>
|
||||
<li><a href="api/env.html">env</a></li>
|
||||
<li><a href="api/fswatch.html">fswatch</a></li>
|
||||
<li><a href="api/html.html">html</a></li>
|
||||
<li><a href="api/http.html">http</a></li>
|
||||
<li><a href="api/io.html">io</a></li>
|
||||
<li><a href="api/pathlib.html">pathlib</a></li>
|
||||
<li><a href="api/scheduler.html">scheduler</a></li>
|
||||
<li><a href="api/jinja.html">jinja</a></li>
|
||||
<li><a href="api/json.html">json</a></li>
|
||||
<li><a href="api/markdown.html">markdown</a></li>
|
||||
<li><a href="api/math.html">math</a></li>
|
||||
<li><a href="api/net.html">net</a></li>
|
||||
<li><a href="api/os.html">os</a></li>
|
||||
<li><a href="api/pathlib.html">pathlib</a></li>
|
||||
<li><a href="api/regex.html">regex</a></li>
|
||||
<li><a href="api/scheduler.html">scheduler</a></li>
|
||||
<li><a href="api/signal.html">signal</a></li>
|
||||
<li><a href="api/sqlite.html">sqlite</a></li>
|
||||
<li><a href="api/subprocess.html">subprocess</a></li>
|
||||
<li><a href="api/sysinfo.html">sysinfo</a></li>
|
||||
<li><a href="api/tempfile.html">tempfile</a></li>
|
||||
<li><a href="api/timer.html">timer</a></li>
|
||||
<li><a href="api/tls.html">tls</a></li>
|
||||
<li><a href="api/udp.html">udp</a></li>
|
||||
<li><a href="api/uuid.html">uuid</a></li>
|
||||
<li><a href="api/wdantic.html">wdantic</a></li>
|
||||
<li><a href="api/web.html">web</a></li>
|
||||
<li><a href="api/websocket.html">websocket</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
@ -113,7 +126,7 @@
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3><a href="api/index.html">API Reference</a></h3>
|
||||
<p>Complete documentation for all 21 built-in modules including HTTP, WebSocket, and SQLite.</p>
|
||||
<p>Complete documentation for all 32 built-in modules including HTTP, WebSocket, and SQLite.</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3><a href="tutorials/index.html">Tutorials</a></h3>
|
||||
@ -130,6 +143,7 @@
|
||||
<a href="api/websocket.html" class="module-card">websocket</a>
|
||||
<a href="api/tls.html" class="module-card">tls</a>
|
||||
<a href="api/net.html" class="module-card">net</a>
|
||||
<a href="api/udp.html" class="module-card">udp</a>
|
||||
<a href="api/dns.html" class="module-card">dns</a>
|
||||
</div>
|
||||
|
||||
@ -150,6 +164,8 @@
|
||||
<a href="api/subprocess.html" class="module-card">subprocess</a>
|
||||
<a href="api/io.html" class="module-card">io</a>
|
||||
<a href="api/pathlib.html" class="module-card">pathlib</a>
|
||||
<a href="api/sysinfo.html" class="module-card">sysinfo</a>
|
||||
<a href="api/fswatch.html" class="module-card">fswatch</a>
|
||||
</div>
|
||||
|
||||
<h3>Data & Time</h3>
|
||||
|
||||
179
src/module/fswatch.c
Normal file
179
src/module/fswatch.c
Normal file
@ -0,0 +1,179 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "fswatch.h"
|
||||
#include "scheduler.h"
|
||||
#include "vm.h"
|
||||
#include "wren.h"
|
||||
#include "uv.h"
|
||||
|
||||
typedef struct {
|
||||
uv_fs_event_t handle;
|
||||
WrenHandle* fiber;
|
||||
WrenHandle* eventClass;
|
||||
char* path;
|
||||
int isActive;
|
||||
int isClosed;
|
||||
} FileWatcherData;
|
||||
|
||||
static WrenHandle* schedulerClass = NULL;
|
||||
static WrenHandle* resumeMethod = NULL;
|
||||
|
||||
static void ensureSchedulerMethods()
|
||||
{
|
||||
if (schedulerClass != NULL) return;
|
||||
|
||||
WrenVM* vm = getVM();
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenGetVariable(vm, "scheduler", "Scheduler", 0);
|
||||
schedulerClass = wrenGetSlotHandle(vm, 0);
|
||||
resumeMethod = wrenMakeCallHandle(vm, "resume_(_,_)");
|
||||
}
|
||||
|
||||
static void resumeFiberWithEvent(WrenHandle* fiber, WrenHandle* event)
|
||||
{
|
||||
WrenVM* vm = getVM();
|
||||
ensureSchedulerMethods();
|
||||
|
||||
wrenEnsureSlots(vm, 3);
|
||||
wrenSetSlotHandle(vm, 0, schedulerClass);
|
||||
wrenSetSlotHandle(vm, 1, fiber);
|
||||
wrenSetSlotHandle(vm, 2, event);
|
||||
|
||||
WrenInterpretResult result = wrenCall(vm, resumeMethod);
|
||||
if (result == WREN_RESULT_RUNTIME_ERROR) {
|
||||
uv_stop(getLoop());
|
||||
setExitCode(70);
|
||||
}
|
||||
}
|
||||
|
||||
static void closeCallback(uv_handle_t* handle)
|
||||
{
|
||||
}
|
||||
|
||||
void fswatchAllocate(WrenVM* vm)
|
||||
{
|
||||
FileWatcherData* data = (FileWatcherData*)wrenSetSlotNewForeign(vm, 0, 0, sizeof(FileWatcherData));
|
||||
memset(data, 0, sizeof(FileWatcherData));
|
||||
|
||||
const char* path = wrenGetSlotString(vm, 1);
|
||||
data->path = strdup(path);
|
||||
data->isActive = 0;
|
||||
data->isClosed = 0;
|
||||
data->fiber = NULL;
|
||||
data->eventClass = NULL;
|
||||
|
||||
uv_fs_event_init(getLoop(), &data->handle);
|
||||
data->handle.data = data;
|
||||
}
|
||||
|
||||
void fswatchFinalize(void* data)
|
||||
{
|
||||
FileWatcherData* watcher = (FileWatcherData*)data;
|
||||
|
||||
if (watcher->path != NULL) {
|
||||
free(watcher->path);
|
||||
watcher->path = NULL;
|
||||
}
|
||||
|
||||
if (!watcher->isClosed && watcher->isActive) {
|
||||
uv_fs_event_stop(&watcher->handle);
|
||||
watcher->isClosed = 1;
|
||||
}
|
||||
|
||||
watcher->isActive = 0;
|
||||
}
|
||||
|
||||
static void eventCallback(uv_fs_event_t* handle, const char* filename, int events, int status)
|
||||
{
|
||||
FileWatcherData* watcher = (FileWatcherData*)handle->data;
|
||||
|
||||
if (!watcher->isActive || watcher->fiber == NULL) return;
|
||||
|
||||
if (status < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
WrenVM* vm = getVM();
|
||||
|
||||
if (watcher->eventClass == NULL) {
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenGetVariable(vm, "fswatch", "FsEvent", 0);
|
||||
watcher->eventClass = wrenGetSlotHandle(vm, 0);
|
||||
}
|
||||
|
||||
wrenEnsureSlots(vm, 4);
|
||||
wrenSetSlotHandle(vm, 0, watcher->eventClass);
|
||||
wrenSetSlotString(vm, 1, filename != NULL ? filename : "");
|
||||
wrenSetSlotDouble(vm, 2, (double)events);
|
||||
|
||||
WrenHandle* constructor = wrenMakeCallHandle(vm, "new(_,_)");
|
||||
WrenInterpretResult result = wrenCall(vm, constructor);
|
||||
wrenReleaseHandle(vm, constructor);
|
||||
|
||||
if (result != WREN_RESULT_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
WrenHandle* event = wrenGetSlotHandle(vm, 0);
|
||||
resumeFiberWithEvent(watcher->fiber, event);
|
||||
wrenReleaseHandle(vm, event);
|
||||
}
|
||||
|
||||
void fswatchStart(WrenVM* vm)
|
||||
{
|
||||
FileWatcherData* watcher = (FileWatcherData*)wrenGetSlotForeign(vm, 0);
|
||||
WrenHandle* fiber = wrenGetSlotHandle(vm, 1);
|
||||
|
||||
if (watcher->isActive) {
|
||||
wrenSetSlotString(vm, 0, "Watcher is already active.");
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
watcher->fiber = fiber;
|
||||
watcher->isActive = 1;
|
||||
|
||||
int result = uv_fs_event_start(&watcher->handle, eventCallback, watcher->path, 0);
|
||||
if (result != 0) {
|
||||
watcher->fiber = NULL;
|
||||
watcher->isActive = 0;
|
||||
wrenReleaseHandle(vm, fiber);
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotNull(vm, 0);
|
||||
}
|
||||
|
||||
void fswatchStop(WrenVM* vm)
|
||||
{
|
||||
FileWatcherData* watcher = (FileWatcherData*)wrenGetSlotForeign(vm, 0);
|
||||
|
||||
if (watcher->isActive) {
|
||||
uv_fs_event_stop(&watcher->handle);
|
||||
watcher->isActive = 0;
|
||||
}
|
||||
|
||||
if (watcher->fiber != NULL) {
|
||||
wrenReleaseHandle(vm, watcher->fiber);
|
||||
watcher->fiber = NULL;
|
||||
}
|
||||
|
||||
if (watcher->eventClass != NULL) {
|
||||
wrenReleaseHandle(vm, watcher->eventClass);
|
||||
watcher->eventClass = NULL;
|
||||
}
|
||||
|
||||
wrenSetSlotNull(vm, 0);
|
||||
}
|
||||
|
||||
void fswatchIsActive(WrenVM* vm)
|
||||
{
|
||||
FileWatcherData* watcher = (FileWatcherData*)wrenGetSlotForeign(vm, 0);
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotBool(vm, 0, watcher->isActive != 0);
|
||||
}
|
||||
14
src/module/fswatch.h
Normal file
14
src/module/fswatch.h
Normal file
@ -0,0 +1,14 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#ifndef fswatch_h
|
||||
#define fswatch_h
|
||||
|
||||
#include "wren.h"
|
||||
|
||||
void fswatchAllocate(WrenVM* vm);
|
||||
void fswatchFinalize(void* data);
|
||||
void fswatchStart(WrenVM* vm);
|
||||
void fswatchStop(WrenVM* vm);
|
||||
void fswatchIsActive(WrenVM* vm);
|
||||
|
||||
#endif
|
||||
41
src/module/fswatch.wren
vendored
Normal file
41
src/module/fswatch.wren
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "scheduler" for Scheduler
|
||||
|
||||
class FsEvent {
|
||||
construct new(filename, events) {
|
||||
_filename = filename
|
||||
_isRename = (events & 1) != 0
|
||||
_isChange = (events & 2) != 0
|
||||
}
|
||||
|
||||
filename { _filename }
|
||||
isRename { _isRename }
|
||||
isChange { _isChange }
|
||||
|
||||
toString { "FsEvent(%(filename), rename: %(isRename), change: %(isChange))" }
|
||||
}
|
||||
|
||||
foreign class FileWatcher {
|
||||
construct new(path) {}
|
||||
|
||||
start(callback) {
|
||||
if (!(callback is Fn)) Fiber.abort("Callback must be a function.")
|
||||
var fiber = Fiber.new {
|
||||
while (true) {
|
||||
var event = Fiber.yield()
|
||||
if (event == null) return
|
||||
callback.call(event)
|
||||
}
|
||||
}
|
||||
fiber.call()
|
||||
start_(fiber)
|
||||
}
|
||||
|
||||
stop() { stop_() }
|
||||
|
||||
foreign isActive
|
||||
|
||||
foreign start_(fiber)
|
||||
foreign stop_()
|
||||
}
|
||||
45
src/module/fswatch.wren.inc
Normal file
45
src/module/fswatch.wren.inc
Normal file
@ -0,0 +1,45 @@
|
||||
// Please do not edit this file. It has been generated automatically
|
||||
// from `src/module/fswatch.wren` using `util/wren_to_c_string.py`
|
||||
|
||||
static const char* fswatchModuleSource =
|
||||
"// retoor <retoor@molodetz.nl>\n"
|
||||
"\n"
|
||||
"import \"scheduler\" for Scheduler\n"
|
||||
"\n"
|
||||
"class FsEvent {\n"
|
||||
" construct new(filename, events) {\n"
|
||||
" _filename = filename\n"
|
||||
" _isRename = (events & 1) != 0\n"
|
||||
" _isChange = (events & 2) != 0\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" filename { _filename }\n"
|
||||
" isRename { _isRename }\n"
|
||||
" isChange { _isChange }\n"
|
||||
"\n"
|
||||
" toString { \"FsEvent(%(filename), rename: %(isRename), change: %(isChange))\" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"foreign class FileWatcher {\n"
|
||||
" construct new(path) {}\n"
|
||||
"\n"
|
||||
" start(callback) {\n"
|
||||
" if (!(callback is Fn)) Fiber.abort(\"Callback must be a function.\")\n"
|
||||
" var fiber = Fiber.new {\n"
|
||||
" while (true) {\n"
|
||||
" var event = Fiber.yield()\n"
|
||||
" if (event == null) return\n"
|
||||
" callback.call(event)\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" fiber.call()\n"
|
||||
" start_(fiber)\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" stop() { stop_() }\n"
|
||||
"\n"
|
||||
" foreign isActive\n"
|
||||
"\n"
|
||||
" foreign start_(fiber)\n"
|
||||
" foreign stop_()\n"
|
||||
"}\n";
|
||||
275
src/module/sysinfo.c
Normal file
275
src/module/sysinfo.c
Normal file
@ -0,0 +1,275 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sysinfo.h"
|
||||
#include "wren.h"
|
||||
#include "uv.h"
|
||||
|
||||
void sysinfoGetCpuInfo(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 4);
|
||||
|
||||
uv_cpu_info_t* cpus;
|
||||
int count;
|
||||
int result = uv_cpu_info(&cpus, &count);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotNewList(vm, 0);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
wrenSetSlotNewMap(vm, 1);
|
||||
|
||||
wrenSetSlotString(vm, 2, "model");
|
||||
wrenSetSlotString(vm, 3, cpus[i].model);
|
||||
wrenSetMapValue(vm, 1, 2, 3);
|
||||
|
||||
wrenSetSlotString(vm, 2, "speed");
|
||||
wrenSetSlotDouble(vm, 3, (double)cpus[i].speed);
|
||||
wrenSetMapValue(vm, 1, 2, 3);
|
||||
|
||||
wrenSetSlotNewMap(vm, 3);
|
||||
|
||||
wrenSetSlotString(vm, 2, "user");
|
||||
wrenSetSlotDouble(vm, 3, (double)cpus[i].cpu_times.user);
|
||||
wrenEnsureSlots(vm, 5);
|
||||
wrenSetSlotNewMap(vm, 4);
|
||||
wrenSetSlotString(vm, 2, "user");
|
||||
wrenSetSlotDouble(vm, 3, (double)cpus[i].cpu_times.user);
|
||||
|
||||
wrenSetSlotNewMap(vm, 2);
|
||||
|
||||
wrenSetSlotString(vm, 3, "user");
|
||||
wrenEnsureSlots(vm, 5);
|
||||
wrenSetSlotDouble(vm, 4, (double)cpus[i].cpu_times.user);
|
||||
wrenSetMapValue(vm, 2, 3, 4);
|
||||
|
||||
wrenSetSlotString(vm, 3, "nice");
|
||||
wrenSetSlotDouble(vm, 4, (double)cpus[i].cpu_times.nice);
|
||||
wrenSetMapValue(vm, 2, 3, 4);
|
||||
|
||||
wrenSetSlotString(vm, 3, "sys");
|
||||
wrenSetSlotDouble(vm, 4, (double)cpus[i].cpu_times.sys);
|
||||
wrenSetMapValue(vm, 2, 3, 4);
|
||||
|
||||
wrenSetSlotString(vm, 3, "idle");
|
||||
wrenSetSlotDouble(vm, 4, (double)cpus[i].cpu_times.idle);
|
||||
wrenSetMapValue(vm, 2, 3, 4);
|
||||
|
||||
wrenSetSlotString(vm, 3, "irq");
|
||||
wrenSetSlotDouble(vm, 4, (double)cpus[i].cpu_times.irq);
|
||||
wrenSetMapValue(vm, 2, 3, 4);
|
||||
|
||||
wrenSetSlotString(vm, 3, "times");
|
||||
wrenSetMapValue(vm, 1, 3, 2);
|
||||
|
||||
wrenInsertInList(vm, 0, -1, 1);
|
||||
}
|
||||
|
||||
uv_free_cpu_info(cpus, count);
|
||||
}
|
||||
|
||||
void sysinfoGetCpuCount(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
|
||||
uv_cpu_info_t* cpus;
|
||||
int count;
|
||||
int result = uv_cpu_info(&cpus, &count);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotDouble(vm, 0, (double)count);
|
||||
uv_free_cpu_info(cpus, count);
|
||||
}
|
||||
|
||||
void sysinfoGetLoadAverage(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 2);
|
||||
|
||||
double avg[3];
|
||||
uv_loadavg(avg);
|
||||
|
||||
wrenSetSlotNewList(vm, 0);
|
||||
|
||||
wrenSetSlotDouble(vm, 1, avg[0]);
|
||||
wrenInsertInList(vm, 0, -1, 1);
|
||||
|
||||
wrenSetSlotDouble(vm, 1, avg[1]);
|
||||
wrenInsertInList(vm, 0, -1, 1);
|
||||
|
||||
wrenSetSlotDouble(vm, 1, avg[2]);
|
||||
wrenInsertInList(vm, 0, -1, 1);
|
||||
}
|
||||
|
||||
void sysinfoGetTotalMemory(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotDouble(vm, 0, (double)uv_get_total_memory());
|
||||
}
|
||||
|
||||
void sysinfoGetFreeMemory(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotDouble(vm, 0, (double)uv_get_free_memory());
|
||||
}
|
||||
|
||||
void sysinfoGetUptime(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
|
||||
double uptime;
|
||||
int result = uv_uptime(&uptime);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotDouble(vm, 0, uptime);
|
||||
}
|
||||
|
||||
void sysinfoGetHostname(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
|
||||
char buffer[UV_MAXHOSTNAMESIZE];
|
||||
size_t size = sizeof(buffer);
|
||||
int result = uv_os_gethostname(buffer, &size);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotString(vm, 0, buffer);
|
||||
}
|
||||
|
||||
void sysinfoGetNetworkInterfaces(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 5);
|
||||
|
||||
uv_interface_address_t* addresses;
|
||||
int count;
|
||||
int result = uv_interface_addresses(&addresses, &count);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotNewMap(vm, 0);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
char ip[INET6_ADDRSTRLEN];
|
||||
wrenSetSlotString(vm, 1, addresses[i].name);
|
||||
|
||||
if (!wrenGetMapContainsKey(vm, 0, 1))
|
||||
{
|
||||
wrenSetSlotNewList(vm, 2);
|
||||
wrenSetMapValue(vm, 0, 1, 2);
|
||||
}
|
||||
|
||||
wrenGetMapValue(vm, 0, 1, 2);
|
||||
|
||||
wrenSetSlotNewMap(vm, 3);
|
||||
|
||||
if (addresses[i].address.address4.sin_family == AF_INET)
|
||||
{
|
||||
uv_ip4_name(&addresses[i].address.address4, ip, sizeof(ip));
|
||||
wrenSetSlotString(vm, 4, "IPv4");
|
||||
}
|
||||
else
|
||||
{
|
||||
uv_ip6_name(&addresses[i].address.address6, ip, sizeof(ip));
|
||||
wrenSetSlotString(vm, 4, "IPv6");
|
||||
}
|
||||
|
||||
wrenSetSlotString(vm, 1, "family");
|
||||
wrenSetMapValue(vm, 3, 1, 4);
|
||||
|
||||
wrenSetSlotString(vm, 1, "address");
|
||||
wrenSetSlotString(vm, 4, ip);
|
||||
wrenSetMapValue(vm, 3, 1, 4);
|
||||
|
||||
wrenSetSlotString(vm, 1, "internal");
|
||||
wrenSetSlotBool(vm, 4, addresses[i].is_internal);
|
||||
wrenSetMapValue(vm, 3, 1, 4);
|
||||
|
||||
char netmask[INET6_ADDRSTRLEN];
|
||||
if (addresses[i].address.address4.sin_family == AF_INET)
|
||||
{
|
||||
uv_ip4_name(&addresses[i].netmask.netmask4, netmask, sizeof(netmask));
|
||||
}
|
||||
else
|
||||
{
|
||||
uv_ip6_name(&addresses[i].netmask.netmask6, netmask, sizeof(netmask));
|
||||
}
|
||||
wrenSetSlotString(vm, 1, "netmask");
|
||||
wrenSetSlotString(vm, 4, netmask);
|
||||
wrenSetMapValue(vm, 3, 1, 4);
|
||||
|
||||
char mac[18];
|
||||
unsigned char* phys = addresses[i].phys_addr;
|
||||
snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
phys[0], phys[1], phys[2], phys[3], phys[4], phys[5]);
|
||||
wrenSetSlotString(vm, 1, "mac");
|
||||
wrenSetSlotString(vm, 4, mac);
|
||||
wrenSetMapValue(vm, 3, 1, 4);
|
||||
|
||||
wrenInsertInList(vm, 2, -1, 3);
|
||||
|
||||
wrenSetSlotString(vm, 1, addresses[i].name);
|
||||
wrenSetMapValue(vm, 0, 1, 2);
|
||||
}
|
||||
|
||||
uv_free_interface_addresses(addresses, count);
|
||||
}
|
||||
|
||||
void sysinfoGetHrtime(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotDouble(vm, 0, (double)uv_hrtime());
|
||||
}
|
||||
|
||||
void sysinfoGetResidentMemory(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
|
||||
size_t rss;
|
||||
int result = uv_resident_set_memory(&rss);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotDouble(vm, 0, (double)rss);
|
||||
}
|
||||
|
||||
void sysinfoGetConstrainedMemory(WrenVM* vm)
|
||||
{
|
||||
wrenEnsureSlots(vm, 1);
|
||||
wrenSetSlotDouble(vm, 0, (double)uv_get_constrained_memory());
|
||||
}
|
||||
20
src/module/sysinfo.h
Normal file
20
src/module/sysinfo.h
Normal file
@ -0,0 +1,20 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#ifndef sysinfo_h
|
||||
#define sysinfo_h
|
||||
|
||||
#include "wren.h"
|
||||
|
||||
void sysinfoGetCpuInfo(WrenVM* vm);
|
||||
void sysinfoGetCpuCount(WrenVM* vm);
|
||||
void sysinfoGetLoadAverage(WrenVM* vm);
|
||||
void sysinfoGetTotalMemory(WrenVM* vm);
|
||||
void sysinfoGetFreeMemory(WrenVM* vm);
|
||||
void sysinfoGetUptime(WrenVM* vm);
|
||||
void sysinfoGetHostname(WrenVM* vm);
|
||||
void sysinfoGetNetworkInterfaces(WrenVM* vm);
|
||||
void sysinfoGetHrtime(WrenVM* vm);
|
||||
void sysinfoGetResidentMemory(WrenVM* vm);
|
||||
void sysinfoGetConstrainedMemory(WrenVM* vm);
|
||||
|
||||
#endif
|
||||
15
src/module/sysinfo.wren
vendored
Normal file
15
src/module/sysinfo.wren
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
class SysInfo {
|
||||
foreign static cpuInfo
|
||||
foreign static cpuCount
|
||||
foreign static loadAverage
|
||||
foreign static totalMemory
|
||||
foreign static freeMemory
|
||||
foreign static uptime
|
||||
foreign static hostname
|
||||
foreign static networkInterfaces
|
||||
foreign static hrtime
|
||||
foreign static residentMemory
|
||||
foreign static constrainedMemory
|
||||
}
|
||||
19
src/module/sysinfo.wren.inc
Normal file
19
src/module/sysinfo.wren.inc
Normal file
@ -0,0 +1,19 @@
|
||||
// Please do not edit this file. It has been generated automatically
|
||||
// from `src/module/sysinfo.wren` using `util/wren_to_c_string.py`
|
||||
|
||||
static const char* sysinfoModuleSource =
|
||||
"// retoor <retoor@molodetz.nl>\n"
|
||||
"\n"
|
||||
"class SysInfo {\n"
|
||||
" foreign static cpuInfo\n"
|
||||
" foreign static cpuCount\n"
|
||||
" foreign static loadAverage\n"
|
||||
" foreign static totalMemory\n"
|
||||
" foreign static freeMemory\n"
|
||||
" foreign static uptime\n"
|
||||
" foreign static hostname\n"
|
||||
" foreign static networkInterfaces\n"
|
||||
" foreign static hrtime\n"
|
||||
" foreign static residentMemory\n"
|
||||
" foreign static constrainedMemory\n"
|
||||
"}\n";
|
||||
384
src/module/udp.c
Normal file
384
src/module/udp.c
Normal file
@ -0,0 +1,384 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "udp.h"
|
||||
#include "scheduler.h"
|
||||
#include "vm.h"
|
||||
#include "wren.h"
|
||||
#include "uv.h"
|
||||
|
||||
typedef struct {
|
||||
uv_udp_t handle;
|
||||
int isClosed;
|
||||
int isReceiving;
|
||||
WrenHandle* receiveFiber;
|
||||
WrenHandle* messageClass;
|
||||
} UdpSocketData;
|
||||
|
||||
typedef struct {
|
||||
WrenHandle* fiber;
|
||||
uv_buf_t buffer;
|
||||
} UdpSendData;
|
||||
|
||||
static void allocCallback(uv_handle_t* handle, size_t suggestedSize, uv_buf_t* buf)
|
||||
{
|
||||
buf->base = (char*)malloc(suggestedSize);
|
||||
buf->len = suggestedSize;
|
||||
}
|
||||
|
||||
void udpSocketAllocate(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* data = (UdpSocketData*)wrenSetSlotNewForeign(vm, 0, 0, sizeof(UdpSocketData));
|
||||
memset(data, 0, sizeof(UdpSocketData));
|
||||
|
||||
uv_udp_init(getLoop(), &data->handle);
|
||||
data->handle.data = data;
|
||||
data->isClosed = 0;
|
||||
data->isReceiving = 0;
|
||||
data->receiveFiber = NULL;
|
||||
data->messageClass = NULL;
|
||||
}
|
||||
|
||||
static void closeCallback(uv_handle_t* handle)
|
||||
{
|
||||
}
|
||||
|
||||
void udpSocketFinalize(void* data)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)data;
|
||||
|
||||
if (!socket->isClosed) {
|
||||
uv_close((uv_handle_t*)&socket->handle, closeCallback);
|
||||
socket->isClosed = 1;
|
||||
}
|
||||
|
||||
if (socket->messageClass != NULL) {
|
||||
socket->messageClass = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void udpSocketBind(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
const char* host = wrenGetSlotString(vm, 1);
|
||||
int port = (int)wrenGetSlotDouble(vm, 2);
|
||||
|
||||
struct sockaddr_storage addr;
|
||||
int result;
|
||||
|
||||
if (strchr(host, ':') != NULL) {
|
||||
result = uv_ip6_addr(host, port, (struct sockaddr_in6*)&addr);
|
||||
} else {
|
||||
result = uv_ip4_addr(host, port, (struct sockaddr_in*)&addr);
|
||||
}
|
||||
|
||||
if (result != 0) {
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
result = uv_udp_bind(&socket->handle, (struct sockaddr*)&addr, 0);
|
||||
if (result != 0) {
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotNull(vm, 0);
|
||||
}
|
||||
|
||||
static void sendCallback(uv_udp_send_t* req, int status)
|
||||
{
|
||||
UdpSendData* data = (UdpSendData*)req->data;
|
||||
WrenHandle* fiber = data->fiber;
|
||||
|
||||
free(data->buffer.base);
|
||||
free(data);
|
||||
free(req);
|
||||
|
||||
if (status != 0) {
|
||||
schedulerResumeError(fiber, uv_strerror(status));
|
||||
return;
|
||||
}
|
||||
|
||||
schedulerResume(fiber, false);
|
||||
}
|
||||
|
||||
void udpSocketSend(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
int dataLen;
|
||||
const char* data = wrenGetSlotBytes(vm, 1, &dataLen);
|
||||
const char* host = wrenGetSlotString(vm, 2);
|
||||
int port = (int)wrenGetSlotDouble(vm, 3);
|
||||
WrenHandle* fiber = wrenGetSlotHandle(vm, 4);
|
||||
|
||||
struct sockaddr_storage addr;
|
||||
int result;
|
||||
|
||||
if (strchr(host, ':') != NULL) {
|
||||
result = uv_ip6_addr(host, port, (struct sockaddr_in6*)&addr);
|
||||
} else {
|
||||
result = uv_ip4_addr(host, port, (struct sockaddr_in*)&addr);
|
||||
}
|
||||
|
||||
if (result != 0) {
|
||||
schedulerResumeError(fiber, uv_strerror(result));
|
||||
return;
|
||||
}
|
||||
|
||||
uv_udp_send_t* req = (uv_udp_send_t*)malloc(sizeof(uv_udp_send_t));
|
||||
UdpSendData* sendData = (UdpSendData*)malloc(sizeof(UdpSendData));
|
||||
|
||||
sendData->fiber = fiber;
|
||||
sendData->buffer.base = (char*)malloc(dataLen);
|
||||
sendData->buffer.len = dataLen;
|
||||
memcpy(sendData->buffer.base, data, dataLen);
|
||||
|
||||
req->data = sendData;
|
||||
|
||||
result = uv_udp_send(req, &socket->handle, &sendData->buffer, 1,
|
||||
(struct sockaddr*)&addr, sendCallback);
|
||||
|
||||
if (result != 0) {
|
||||
free(sendData->buffer.base);
|
||||
free(sendData);
|
||||
free(req);
|
||||
schedulerResumeError(fiber, uv_strerror(result));
|
||||
}
|
||||
}
|
||||
|
||||
static void recvCallback(uv_udp_t* handle, ssize_t nread, const uv_buf_t* buf,
|
||||
const struct sockaddr* addr, unsigned flags)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)handle->data;
|
||||
|
||||
if (socket->receiveFiber == NULL) {
|
||||
if (buf->base != NULL) free(buf->base);
|
||||
return;
|
||||
}
|
||||
|
||||
uv_udp_recv_stop(handle);
|
||||
socket->isReceiving = 0;
|
||||
|
||||
WrenHandle* fiber = socket->receiveFiber;
|
||||
socket->receiveFiber = NULL;
|
||||
|
||||
if (nread < 0) {
|
||||
if (buf->base != NULL) free(buf->base);
|
||||
schedulerResumeError(fiber, uv_strerror(nread));
|
||||
return;
|
||||
}
|
||||
|
||||
if (nread == 0 && addr == NULL) {
|
||||
if (buf->base != NULL) free(buf->base);
|
||||
schedulerResume(fiber, true);
|
||||
wrenSetSlotNull(getVM(), 2);
|
||||
schedulerFinishResume();
|
||||
return;
|
||||
}
|
||||
|
||||
WrenVM* vm = getVM();
|
||||
wrenEnsureSlots(vm, 5);
|
||||
|
||||
if (socket->messageClass == NULL) {
|
||||
wrenGetVariable(vm, "udp", "UdpMessage", 3);
|
||||
socket->messageClass = wrenGetSlotHandle(vm, 3);
|
||||
}
|
||||
|
||||
wrenSetSlotHandle(vm, 3, socket->messageClass);
|
||||
wrenSetSlotBytes(vm, 4, buf->base, nread);
|
||||
|
||||
char addrStr[INET6_ADDRSTRLEN];
|
||||
int port;
|
||||
|
||||
if (addr->sa_family == AF_INET) {
|
||||
struct sockaddr_in* addr4 = (struct sockaddr_in*)addr;
|
||||
uv_ip4_name(addr4, addrStr, sizeof(addrStr));
|
||||
port = ntohs(addr4->sin_port);
|
||||
} else {
|
||||
struct sockaddr_in6* addr6 = (struct sockaddr_in6*)addr;
|
||||
uv_ip6_name(addr6, addrStr, sizeof(addrStr));
|
||||
port = ntohs(addr6->sin6_port);
|
||||
}
|
||||
|
||||
free(buf->base);
|
||||
|
||||
wrenSetSlotNewList(vm, 2);
|
||||
wrenSetSlotString(vm, 1, addrStr);
|
||||
wrenInsertInList(vm, 2, -1, 4);
|
||||
wrenInsertInList(vm, 2, -1, 1);
|
||||
wrenSetSlotDouble(vm, 1, (double)port);
|
||||
wrenInsertInList(vm, 2, -1, 1);
|
||||
|
||||
schedulerResume(fiber, true);
|
||||
schedulerFinishResume();
|
||||
}
|
||||
|
||||
void udpSocketReceive(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
WrenHandle* fiber = wrenGetSlotHandle(vm, 1);
|
||||
|
||||
if (socket->isReceiving) {
|
||||
schedulerResumeError(fiber, "Already receiving.");
|
||||
return;
|
||||
}
|
||||
|
||||
socket->receiveFiber = fiber;
|
||||
socket->isReceiving = 1;
|
||||
|
||||
int result = uv_udp_recv_start(&socket->handle, allocCallback, recvCallback);
|
||||
if (result != 0) {
|
||||
socket->receiveFiber = NULL;
|
||||
socket->isReceiving = 0;
|
||||
schedulerResumeError(fiber, uv_strerror(result));
|
||||
}
|
||||
}
|
||||
|
||||
void udpSocketClose(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
|
||||
if (!socket->isClosed) {
|
||||
if (socket->isReceiving) {
|
||||
uv_udp_recv_stop(&socket->handle);
|
||||
socket->isReceiving = 0;
|
||||
}
|
||||
uv_close((uv_handle_t*)&socket->handle, closeCallback);
|
||||
socket->isClosed = 1;
|
||||
}
|
||||
|
||||
if (socket->messageClass != NULL) {
|
||||
wrenReleaseHandle(vm, socket->messageClass);
|
||||
socket->messageClass = NULL;
|
||||
}
|
||||
|
||||
wrenSetSlotNull(vm, 0);
|
||||
}
|
||||
|
||||
void udpSocketSetBroadcast(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
bool enabled = wrenGetSlotBool(vm, 1);
|
||||
|
||||
int result = uv_udp_set_broadcast(&socket->handle, enabled ? 1 : 0);
|
||||
if (result != 0) {
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotNull(vm, 0);
|
||||
}
|
||||
|
||||
void udpSocketSetMulticastTTL(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
int ttl = (int)wrenGetSlotDouble(vm, 1);
|
||||
|
||||
int result = uv_udp_set_multicast_ttl(&socket->handle, ttl);
|
||||
if (result != 0) {
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotNull(vm, 0);
|
||||
}
|
||||
|
||||
void udpSocketSetMulticastLoopback(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
bool enabled = wrenGetSlotBool(vm, 1);
|
||||
|
||||
int result = uv_udp_set_multicast_loop(&socket->handle, enabled ? 1 : 0);
|
||||
if (result != 0) {
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotNull(vm, 0);
|
||||
}
|
||||
|
||||
void udpSocketJoinMulticast(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
const char* group = wrenGetSlotString(vm, 1);
|
||||
const char* iface = wrenGetSlotString(vm, 2);
|
||||
|
||||
int result = uv_udp_set_membership(&socket->handle, group, iface, UV_JOIN_GROUP);
|
||||
if (result != 0) {
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotNull(vm, 0);
|
||||
}
|
||||
|
||||
void udpSocketLeaveMulticast(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
const char* group = wrenGetSlotString(vm, 1);
|
||||
const char* iface = wrenGetSlotString(vm, 2);
|
||||
|
||||
int result = uv_udp_set_membership(&socket->handle, group, iface, UV_LEAVE_GROUP);
|
||||
if (result != 0) {
|
||||
wrenSetSlotString(vm, 0, uv_strerror(result));
|
||||
wrenAbortFiber(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
wrenSetSlotNull(vm, 0);
|
||||
}
|
||||
|
||||
void udpSocketLocalAddress(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
|
||||
struct sockaddr_storage addr;
|
||||
int len = sizeof(addr);
|
||||
int result = uv_udp_getsockname(&socket->handle, (struct sockaddr*)&addr, &len);
|
||||
|
||||
if (result != 0) {
|
||||
wrenSetSlotNull(vm, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
char addrStr[INET6_ADDRSTRLEN];
|
||||
if (addr.ss_family == AF_INET) {
|
||||
uv_ip4_name((struct sockaddr_in*)&addr, addrStr, sizeof(addrStr));
|
||||
} else {
|
||||
uv_ip6_name((struct sockaddr_in6*)&addr, addrStr, sizeof(addrStr));
|
||||
}
|
||||
|
||||
wrenSetSlotString(vm, 0, addrStr);
|
||||
}
|
||||
|
||||
void udpSocketLocalPort(WrenVM* vm)
|
||||
{
|
||||
UdpSocketData* socket = (UdpSocketData*)wrenGetSlotForeign(vm, 0);
|
||||
|
||||
struct sockaddr_storage addr;
|
||||
int len = sizeof(addr);
|
||||
int result = uv_udp_getsockname(&socket->handle, (struct sockaddr*)&addr, &len);
|
||||
|
||||
if (result != 0) {
|
||||
wrenSetSlotDouble(vm, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
int port;
|
||||
if (addr.ss_family == AF_INET) {
|
||||
port = ntohs(((struct sockaddr_in*)&addr)->sin_port);
|
||||
} else {
|
||||
port = ntohs(((struct sockaddr_in6*)&addr)->sin6_port);
|
||||
}
|
||||
|
||||
wrenSetSlotDouble(vm, 0, (double)port);
|
||||
}
|
||||
22
src/module/udp.h
Normal file
22
src/module/udp.h
Normal file
@ -0,0 +1,22 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#ifndef udp_h
|
||||
#define udp_h
|
||||
|
||||
#include "wren.h"
|
||||
|
||||
void udpSocketAllocate(WrenVM* vm);
|
||||
void udpSocketFinalize(void* data);
|
||||
void udpSocketBind(WrenVM* vm);
|
||||
void udpSocketSend(WrenVM* vm);
|
||||
void udpSocketReceive(WrenVM* vm);
|
||||
void udpSocketClose(WrenVM* vm);
|
||||
void udpSocketSetBroadcast(WrenVM* vm);
|
||||
void udpSocketSetMulticastTTL(WrenVM* vm);
|
||||
void udpSocketSetMulticastLoopback(WrenVM* vm);
|
||||
void udpSocketJoinMulticast(WrenVM* vm);
|
||||
void udpSocketLeaveMulticast(WrenVM* vm);
|
||||
void udpSocketLocalAddress(WrenVM* vm);
|
||||
void udpSocketLocalPort(WrenVM* vm);
|
||||
|
||||
#endif
|
||||
90
src/module/udp.wren
vendored
Normal file
90
src/module/udp.wren
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "scheduler" for Scheduler
|
||||
|
||||
foreign class UdpSocket {
|
||||
construct new() {}
|
||||
|
||||
bind(host, port) {
|
||||
if (!(host is String)) Fiber.abort("Host must be a string.")
|
||||
if (!(port is Num)) Fiber.abort("Port must be a number.")
|
||||
return bind_(host, port)
|
||||
}
|
||||
|
||||
send(data, host, port) {
|
||||
if (!(data is String)) Fiber.abort("Data must be a string.")
|
||||
if (!(host is String)) Fiber.abort("Host must be a string.")
|
||||
if (!(port is Num)) Fiber.abort("Port must be a number.")
|
||||
return Scheduler.await_ { send_(data, host, port, Fiber.current) }
|
||||
}
|
||||
|
||||
receive() {
|
||||
return Scheduler.await_ { receive_(Fiber.current) }
|
||||
}
|
||||
|
||||
close() { close_() }
|
||||
|
||||
setBroadcast(enabled) {
|
||||
if (!(enabled is Bool)) Fiber.abort("Enabled must be a boolean.")
|
||||
return setBroadcast_(enabled)
|
||||
}
|
||||
|
||||
setMulticastTTL(ttl) {
|
||||
if (!(ttl is Num)) Fiber.abort("TTL must be a number.")
|
||||
return setMulticastTTL_(ttl)
|
||||
}
|
||||
|
||||
setMulticastLoopback(enabled) {
|
||||
if (!(enabled is Bool)) Fiber.abort("Enabled must be a boolean.")
|
||||
return setMulticastLoopback_(enabled)
|
||||
}
|
||||
|
||||
joinMulticast(group) {
|
||||
if (!(group is String)) Fiber.abort("Group must be a string.")
|
||||
return joinMulticast_(group, "0.0.0.0")
|
||||
}
|
||||
|
||||
joinMulticast(group, iface) {
|
||||
if (!(group is String)) Fiber.abort("Group must be a string.")
|
||||
if (!(iface is String)) Fiber.abort("Interface must be a string.")
|
||||
return joinMulticast_(group, iface)
|
||||
}
|
||||
|
||||
leaveMulticast(group) {
|
||||
if (!(group is String)) Fiber.abort("Group must be a string.")
|
||||
return leaveMulticast_(group, "0.0.0.0")
|
||||
}
|
||||
|
||||
leaveMulticast(group, iface) {
|
||||
if (!(group is String)) Fiber.abort("Group must be a string.")
|
||||
if (!(iface is String)) Fiber.abort("Interface must be a string.")
|
||||
return leaveMulticast_(group, iface)
|
||||
}
|
||||
|
||||
foreign localAddress
|
||||
foreign localPort
|
||||
|
||||
foreign bind_(host, port)
|
||||
foreign send_(data, host, port, fiber)
|
||||
foreign receive_(fiber)
|
||||
foreign close_()
|
||||
foreign setBroadcast_(enabled)
|
||||
foreign setMulticastTTL_(ttl)
|
||||
foreign setMulticastLoopback_(enabled)
|
||||
foreign joinMulticast_(group, iface)
|
||||
foreign leaveMulticast_(group, iface)
|
||||
}
|
||||
|
||||
class UdpMessage {
|
||||
construct new(data, address, port) {
|
||||
_data = data
|
||||
_address = address
|
||||
_port = port
|
||||
}
|
||||
|
||||
data { _data }
|
||||
address { _address }
|
||||
port { _port }
|
||||
|
||||
toString { "UdpMessage(%(data.count) bytes from %(address):%(port))" }
|
||||
}
|
||||
94
src/module/udp.wren.inc
Normal file
94
src/module/udp.wren.inc
Normal file
@ -0,0 +1,94 @@
|
||||
// Please do not edit this file. It has been generated automatically
|
||||
// from `src/module/udp.wren` using `util/wren_to_c_string.py`
|
||||
|
||||
static const char* udpModuleSource =
|
||||
"// retoor <retoor@molodetz.nl>\n"
|
||||
"\n"
|
||||
"import \"scheduler\" for Scheduler\n"
|
||||
"\n"
|
||||
"foreign class UdpSocket {\n"
|
||||
" construct new() {}\n"
|
||||
"\n"
|
||||
" bind(host, port) {\n"
|
||||
" if (!(host is String)) Fiber.abort(\"Host must be a string.\")\n"
|
||||
" if (!(port is Num)) Fiber.abort(\"Port must be a number.\")\n"
|
||||
" return bind_(host, port)\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" send(data, host, port) {\n"
|
||||
" if (!(data is String)) Fiber.abort(\"Data must be a string.\")\n"
|
||||
" if (!(host is String)) Fiber.abort(\"Host must be a string.\")\n"
|
||||
" if (!(port is Num)) Fiber.abort(\"Port must be a number.\")\n"
|
||||
" return Scheduler.await_ { send_(data, host, port, Fiber.current) }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" receive() {\n"
|
||||
" return Scheduler.await_ { receive_(Fiber.current) }\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" close() { close_() }\n"
|
||||
"\n"
|
||||
" setBroadcast(enabled) {\n"
|
||||
" if (!(enabled is Bool)) Fiber.abort(\"Enabled must be a boolean.\")\n"
|
||||
" return setBroadcast_(enabled)\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" setMulticastTTL(ttl) {\n"
|
||||
" if (!(ttl is Num)) Fiber.abort(\"TTL must be a number.\")\n"
|
||||
" return setMulticastTTL_(ttl)\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" setMulticastLoopback(enabled) {\n"
|
||||
" if (!(enabled is Bool)) Fiber.abort(\"Enabled must be a boolean.\")\n"
|
||||
" return setMulticastLoopback_(enabled)\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" joinMulticast(group) {\n"
|
||||
" if (!(group is String)) Fiber.abort(\"Group must be a string.\")\n"
|
||||
" return joinMulticast_(group, \"0.0.0.0\")\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" joinMulticast(group, iface) {\n"
|
||||
" if (!(group is String)) Fiber.abort(\"Group must be a string.\")\n"
|
||||
" if (!(iface is String)) Fiber.abort(\"Interface must be a string.\")\n"
|
||||
" return joinMulticast_(group, iface)\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" leaveMulticast(group) {\n"
|
||||
" if (!(group is String)) Fiber.abort(\"Group must be a string.\")\n"
|
||||
" return leaveMulticast_(group, \"0.0.0.0\")\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" leaveMulticast(group, iface) {\n"
|
||||
" if (!(group is String)) Fiber.abort(\"Group must be a string.\")\n"
|
||||
" if (!(iface is String)) Fiber.abort(\"Interface must be a string.\")\n"
|
||||
" return leaveMulticast_(group, iface)\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" foreign localAddress\n"
|
||||
" foreign localPort\n"
|
||||
"\n"
|
||||
" foreign bind_(host, port)\n"
|
||||
" foreign send_(data, host, port, fiber)\n"
|
||||
" foreign receive_(fiber)\n"
|
||||
" foreign close_()\n"
|
||||
" foreign setBroadcast_(enabled)\n"
|
||||
" foreign setMulticastTTL_(ttl)\n"
|
||||
" foreign setMulticastLoopback_(enabled)\n"
|
||||
" foreign joinMulticast_(group, iface)\n"
|
||||
" foreign leaveMulticast_(group, iface)\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"class UdpMessage {\n"
|
||||
" construct new(data, address, port) {\n"
|
||||
" _data = data\n"
|
||||
" _address = address\n"
|
||||
" _port = port\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" data { _data }\n"
|
||||
" address { _address }\n"
|
||||
" port { _port }\n"
|
||||
"\n"
|
||||
" toString { \"UdpMessage(%(data.count) bytes from %(address):%(port))\" }\n"
|
||||
"}\n";
|
||||
34
test/fswatch/watch_file.wren
vendored
Normal file
34
test/fswatch/watch_file.wren
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "fswatch" for FileWatcher, FsEvent
|
||||
import "timer" for Timer
|
||||
import "io" for File, FileFlags
|
||||
|
||||
var testFile = "/tmp/fswatch_test_%(Num.fromString("%(System.clock)".split(".")[1])).txt"
|
||||
|
||||
var f = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.create | FileFlags.truncate)
|
||||
f.writeBytes("initial", 0)
|
||||
f.close()
|
||||
|
||||
var watcher = FileWatcher.new(testFile)
|
||||
var received = []
|
||||
|
||||
watcher.start { |event|
|
||||
received.add(event)
|
||||
}
|
||||
|
||||
System.print(watcher.isActive) // expect: true
|
||||
|
||||
Timer.immediate {
|
||||
var f2 = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.truncate)
|
||||
f2.writeBytes("modified", 0)
|
||||
f2.close()
|
||||
}
|
||||
|
||||
Timer.sleep(100)
|
||||
|
||||
System.print(received.count > 0) // expect: true
|
||||
System.print(received[0] is FsEvent) // expect: true
|
||||
|
||||
watcher.stop()
|
||||
System.print(watcher.isActive) // expect: false
|
||||
17
test/io/file/copy.wren
vendored
Normal file
17
test/io/file/copy.wren
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "io" for File
|
||||
|
||||
var srcFile = "/tmp/test_copy_src.txt"
|
||||
var dstFile = "/tmp/test_copy_dst.txt"
|
||||
var content = "Copy me!"
|
||||
|
||||
File.write(srcFile, content)
|
||||
|
||||
File.copy(srcFile, dstFile)
|
||||
|
||||
System.print(File.exists(dstFile)) // expect: true
|
||||
System.print(File.read(dstFile) == content) // expect: true
|
||||
|
||||
File.delete(srcFile)
|
||||
File.delete(dstFile)
|
||||
17
test/io/file/move.wren
vendored
Normal file
17
test/io/file/move.wren
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "io" for File
|
||||
|
||||
var srcFile = "/tmp/test_move_src.txt"
|
||||
var dstFile = "/tmp/test_move_dst.txt"
|
||||
var content = "Move me!"
|
||||
|
||||
File.write(srcFile, content)
|
||||
|
||||
File.move(srcFile, dstFile)
|
||||
|
||||
System.print(File.exists(srcFile)) // expect: false
|
||||
System.print(File.exists(dstFile)) // expect: true
|
||||
System.print(File.read(dstFile) == content) // expect: true
|
||||
|
||||
File.delete(dstFile)
|
||||
13
test/io/file/write_static.wren
vendored
Normal file
13
test/io/file/write_static.wren
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "io" for File
|
||||
|
||||
var testFile = "/tmp/test_write_static.txt"
|
||||
var content = "Hello, World!"
|
||||
|
||||
File.write(testFile, content)
|
||||
|
||||
var read = File.read(testFile)
|
||||
System.print(read == content) // expect: true
|
||||
|
||||
File.delete(testFile)
|
||||
13
test/io/window_size.wren
vendored
Normal file
13
test/io/window_size.wren
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "io" for Stdin
|
||||
|
||||
var size = Stdin.windowSize
|
||||
|
||||
System.print(size == null || size is List) // expect: true
|
||||
|
||||
if (size != null) {
|
||||
System.print(size.count == 2)
|
||||
System.print(size[0] > 0)
|
||||
System.print(size[1] > 0)
|
||||
}
|
||||
12
test/pathlib/size.wren
vendored
Normal file
12
test/pathlib/size.wren
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "pathlib" for Path
|
||||
|
||||
var testFile = Path.new("/tmp/test_pathlib_size.txt")
|
||||
var content = "12345678"
|
||||
testFile.writeText(content)
|
||||
|
||||
var size = testFile.size()
|
||||
System.print(size) // expect: 8
|
||||
|
||||
testFile.unlink()
|
||||
19
test/pathlib/stat_times.wren
vendored
Normal file
19
test/pathlib/stat_times.wren
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "pathlib" for Path
|
||||
|
||||
var testFile = Path.new("/tmp/test_pathlib_stat_times.txt")
|
||||
testFile.writeText("test content")
|
||||
|
||||
var mtime = testFile.mtime()
|
||||
var atime = testFile.atime()
|
||||
var ctime = testFile.ctime()
|
||||
|
||||
System.print(mtime is Num) // expect: true
|
||||
System.print(atime is Num) // expect: true
|
||||
System.print(ctime is Num) // expect: true
|
||||
System.print(mtime > 0) // expect: true
|
||||
System.print(atime > 0) // expect: true
|
||||
System.print(ctime > 0) // expect: true
|
||||
|
||||
testFile.unlink()
|
||||
7
test/sysinfo/cpu_count.wren
vendored
Normal file
7
test/sysinfo/cpu_count.wren
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var count = SysInfo.cpuCount
|
||||
System.print(count is Num) // expect: true
|
||||
System.print(count > 0) // expect: true
|
||||
19
test/sysinfo/cpu_info.wren
vendored
Normal file
19
test/sysinfo/cpu_info.wren
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var cpus = SysInfo.cpuInfo
|
||||
System.print(cpus is List) // expect: true
|
||||
System.print(cpus.count > 0) // expect: true
|
||||
|
||||
var cpu = cpus[0]
|
||||
System.print(cpu is Map) // expect: true
|
||||
System.print(cpu.containsKey("model")) // expect: true
|
||||
System.print(cpu.containsKey("speed")) // expect: true
|
||||
System.print(cpu.containsKey("times")) // expect: true
|
||||
|
||||
var times = cpu["times"]
|
||||
System.print(times is Map) // expect: true
|
||||
System.print(times.containsKey("user")) // expect: true
|
||||
System.print(times.containsKey("sys")) // expect: true
|
||||
System.print(times.containsKey("idle")) // expect: true
|
||||
7
test/sysinfo/hostname.wren
vendored
Normal file
7
test/sysinfo/hostname.wren
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var hostname = SysInfo.hostname
|
||||
System.print(hostname is String) // expect: true
|
||||
System.print(hostname.count > 0) // expect: true
|
||||
9
test/sysinfo/hrtime.wren
vendored
Normal file
9
test/sysinfo/hrtime.wren
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var t1 = SysInfo.hrtime
|
||||
var t2 = SysInfo.hrtime
|
||||
System.print(t1 is Num) // expect: true
|
||||
System.print(t2 is Num) // expect: true
|
||||
System.print(t2 >= t1) // expect: true
|
||||
10
test/sysinfo/load_average.wren
vendored
Normal file
10
test/sysinfo/load_average.wren
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var load = SysInfo.loadAverage
|
||||
System.print(load is List) // expect: true
|
||||
System.print(load.count) // expect: 3
|
||||
System.print(load[0] is Num) // expect: true
|
||||
System.print(load[1] is Num) // expect: true
|
||||
System.print(load[2] is Num) // expect: true
|
||||
16
test/sysinfo/memory.wren
vendored
Normal file
16
test/sysinfo/memory.wren
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var total = SysInfo.totalMemory
|
||||
var free = SysInfo.freeMemory
|
||||
var resident = SysInfo.residentMemory
|
||||
|
||||
System.print(total is Num) // expect: true
|
||||
System.print(free is Num) // expect: true
|
||||
System.print(resident is Num) // expect: true
|
||||
|
||||
System.print(total > 0) // expect: true
|
||||
System.print(free > 0) // expect: true
|
||||
System.print(resident > 0) // expect: true
|
||||
System.print(total >= free) // expect: true
|
||||
23
test/sysinfo/network_interfaces.wren
vendored
Normal file
23
test/sysinfo/network_interfaces.wren
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var interfaces = SysInfo.networkInterfaces
|
||||
System.print(interfaces is Map) // expect: true
|
||||
System.print(interfaces.count > 0) // expect: true
|
||||
|
||||
for (name in interfaces.keys) {
|
||||
var addrs = interfaces[name]
|
||||
System.print(addrs is List) // expect: true
|
||||
|
||||
for (addr in addrs) {
|
||||
System.print(addr is Map) // expect: true
|
||||
System.print(addr.containsKey("family")) // expect: true
|
||||
System.print(addr.containsKey("address")) // expect: true
|
||||
System.print(addr.containsKey("internal")) // expect: true
|
||||
System.print(addr.containsKey("netmask")) // expect: true
|
||||
System.print(addr.containsKey("mac")) // expect: true
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
7
test/sysinfo/uptime.wren
vendored
Normal file
7
test/sysinfo/uptime.wren
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "sysinfo" for SysInfo
|
||||
|
||||
var uptime = SysInfo.uptime
|
||||
System.print(uptime is Num) // expect: true
|
||||
System.print(uptime > 0) // expect: true
|
||||
15
test/timer/immediate.wren
vendored
Normal file
15
test/timer/immediate.wren
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "timer" for Timer
|
||||
|
||||
var called = false
|
||||
|
||||
Timer.immediate {
|
||||
called = true
|
||||
}
|
||||
|
||||
System.print(called) // expect: false
|
||||
|
||||
Timer.sleep(1)
|
||||
|
||||
System.print(called) // expect: true
|
||||
20
test/timer/interval.wren
vendored
Normal file
20
test/timer/interval.wren
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "timer" for Timer, TimerHandle
|
||||
|
||||
var count = 0
|
||||
var handle = Timer.interval(1) {
|
||||
count = count + 1
|
||||
}
|
||||
|
||||
System.print(handle is TimerHandle) // expect: true
|
||||
System.print(handle.isActive) // expect: true
|
||||
|
||||
Timer.sleep(100)
|
||||
handle.stop()
|
||||
|
||||
System.print(count > 0) // expect: true
|
||||
System.print(handle.isActive) // expect: false
|
||||
|
||||
|
||||
System.print(count) // nontest
|
||||
6
test/timer/sleep.wren
vendored
Normal file
6
test/timer/sleep.wren
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "timer" for Timer
|
||||
|
||||
Timer.sleep(10)
|
||||
System.print("after sleep") // expect: after sleep
|
||||
11
test/udp/bind.wren
vendored
Normal file
11
test/udp/bind.wren
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "udp" for UdpSocket
|
||||
|
||||
var socket = UdpSocket.new()
|
||||
socket.bind("127.0.0.1", 0)
|
||||
|
||||
System.print(socket.localAddress) // expect: 127.0.0.1
|
||||
System.print(socket.localPort > 0) // expect: true
|
||||
|
||||
socket.close()
|
||||
9
test/udp/broadcast.wren
vendored
Normal file
9
test/udp/broadcast.wren
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "udp" for UdpSocket
|
||||
|
||||
var socket = UdpSocket.new()
|
||||
socket.bind("0.0.0.0", 0)
|
||||
socket.setBroadcast(true)
|
||||
System.print("broadcast enabled") // expect: broadcast enabled
|
||||
socket.close()
|
||||
30
test/udp/send_receive.wren
vendored
Normal file
30
test/udp/send_receive.wren
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "udp" for UdpSocket
|
||||
import "timer" for Timer
|
||||
import "scheduler" for Scheduler
|
||||
|
||||
var server = UdpSocket.new()
|
||||
server.bind("127.0.0.1", 0)
|
||||
var serverPort = server.localPort
|
||||
|
||||
var received = null
|
||||
|
||||
Scheduler.add {
|
||||
received = server.receive()
|
||||
server.close()
|
||||
}
|
||||
|
||||
var client = UdpSocket.new()
|
||||
client.bind("127.0.0.1", 0)
|
||||
|
||||
Timer.immediate {
|
||||
client.send("test", "127.0.0.1", serverPort)
|
||||
client.close()
|
||||
}
|
||||
|
||||
Timer.sleep(100)
|
||||
|
||||
System.print(received != null) // expect: true
|
||||
System.print(received[0]) // expect: test
|
||||
System.print(received[1]) // expect: 127.0.0.1
|
||||
Loading…
Reference in New Issue
Block a user