Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F167302816
D57660.id180054.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
11 KB
Referenced Files
None
Subscribers
None
D57660.id180054.diff
View Options
diff --git a/libexec/flua/libucl/Makefile b/libexec/flua/libucl/Makefile
--- a/libexec/flua/libucl/Makefile
+++ b/libexec/flua/libucl/Makefile
@@ -1,4 +1,7 @@
SHLIB_NAME= ucl.so
.include "Makefile.inc"
+
+MAN= ucl.3lua
+
.include <bsd.lib.mk>
diff --git a/libexec/flua/libucl/ucl.3lua b/libexec/flua/libucl/ucl.3lua
new file mode 100644
--- /dev/null
+++ b/libexec/flua/libucl/ucl.3lua
@@ -0,0 +1,66 @@
+.\"
+.\" Copyright (c) 2024 FreeBSD
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd February 6, 2024
+.Dt UCL 3lua
+.Os
+.Sh NAME
+.Nm parser_new ,
+.Nm parser_register_variable ,
+.Nm parser_add_chunk ,
+.Nm parser_get_object ,
+.Nm object_validate
+.Nd Universal Configuration Language (UCL) Lua interface
+.Sh DESCRIPTION
+The
+.Nm ucl
+module provides functions for parsing and manipulating UCL configuration data.
+.Ss APIs Supported
+.Bl -tag -width indent
+.It Fn parser_new
+Creates a new UCL parser instance.
+.It Fn parser_register_variable name value
+Registers a variable that can be used in UCL macros.
+.It Fn parser_add_chunk data [priority]
+Adds a chunk of UCL data to be parsed. Optional priority determines merge order.
+.It Fn parser_get_object
+Returns the parsed UCL object.
+.It Fn object_validate schema
+Validates a UCL object against a schema definition.
+.El
+.Sh EXAMPLES
+Parse a UCL configuration:
+.Bd -literal -offset indent
+local ucl = require "ucl"
+local parser = ucl.parser_new()
+parser:add_chunk([[
+ server {
+ host = "localhost";
+ port = 8080;
+ }
+]])
+local obj = parser:get_object()
+print(obj.server.host) -- prints "localhost"
+.Ed
+.Pp
+Use variables in UCL:
+.Bd -literal -offset indent
+local parser = ucl.parser_new()
+parser:register_variable("HOSTNAME", "example.com")
+parser:add_chunk([[
+ domain = "$HOSTNAME";
+]])
+local obj = parser:get_object()
+print(obj.domain) -- prints "example.com"
+.Ed
+.Sh SEE ALSO
+.Xr lua 1 ,
+.Xr libucl 3 ,
+.Xr ucl 5
+.Sh AUTHORS
+The
+.Nm
+man page was written by
+.An FreeBSD
diff --git a/libexec/flua/modules/fbsd.3lua b/libexec/flua/modules/fbsd.3lua
new file mode 100644
--- /dev/null
+++ b/libexec/flua/modules/fbsd.3lua
@@ -0,0 +1,36 @@
+.\"
+.\" Copyright (c) 2024 FreeBSD
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd February 6, 2024
+.Dt FBSD 3lua
+.Os
+.Sh NAME
+.Nm exec
+.Nd FreeBSD-specific Lua operations module
+.Sh DESCRIPTION
+The
+.Nm fbsd
+module provides FreeBSD-specific operations for Lua programs.
+.Ss APIs Supported
+.Bl -tag -width indent
+.It Fn exec path [args]
+Executes a program at the specified path with optional arguments.
+The current process is replaced with the new program.
+.El
+.Sh EXAMPLES
+Execute a command:
+.Bd -literal -offset indent
+local fbsd = require "fbsd"
+fbsd.exec("/bin/ls", {"-l", "/tmp"})
+.Ed
+.Sh SEE ALSO
+.Xr lua 1 ,
+.Xr execve 2 ,
+.Xr luaopen_fbsd 3
+.Sh AUTHORS
+The
+.Nm
+man page was written by
+.An FreeBSD
diff --git a/libexec/flua/modules/lfs.3lua b/libexec/flua/modules/lfs.3lua
new file mode 100644
--- /dev/null
+++ b/libexec/flua/modules/lfs.3lua
@@ -0,0 +1,60 @@
+.\"
+.\" Copyright (c) 2024 FreeBSD
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd February 6, 2024
+.Dt LFS 3lua
+.Os
+.Sh NAME
+.Nm attributes ,
+.Nm dir ,
+.Nm link ,
+.Nm mkdir ,
+.Nm rmdir ,
+.Nm touch ,
+.Nm unlock
+.Nd Lua filesystem operations module
+.Sh DESCRIPTION
+The
+.Nm lfs
+module provides filesystem operations for Lua programs.
+.Ss APIs Supported
+.Bl -tag -width indent
+.It Fn attributes path [mode]
+Returns a table with file attributes.
+Mode can be "modification", "access", "change", "size", "permissions", "uid", "gid", "type", "blocks", "blksize", or "device".
+.It Fn dir path
+Returns an iterator to list directory contents.
+.It Fn link oldpath newpath [symlink]
+Creates a link. If symlink is true, creates a symbolic link.
+.It Fn mkdir path
+Creates a new directory.
+.It Fn rmdir path
+Removes an empty directory.
+.It Fn touch path [atime] [mtime]
+Sets access and modification times of a file.
+.It Fn unlock handle
+Unlocks a file or a part of it.
+.El
+.Sh EXAMPLES
+List directory contents:
+.Bd -literal -offset indent
+for file in lfs.dir(".") do
+ print(file)
+end
+.Ed
+.Pp
+Get file attributes:
+.Bd -literal -offset indent
+attrs = lfs.attributes("file.txt")
+print(attrs.size)
+.Ed
+.Sh SEE ALSO
+.Xr lua 1 ,
+.Xr luaopen_lfs 3
+.Sh AUTHORS
+The
+.Nm
+man page was written by
+.An FreeBSD
diff --git a/libexec/flua/modules/lposix.3lua b/libexec/flua/modules/lposix.3lua
new file mode 100644
--- /dev/null
+++ b/libexec/flua/modules/lposix.3lua
@@ -0,0 +1,107 @@
+.\"
+.\" Copyright (c) 2024 FreeBSD
+.\"
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.Dd February 6, 2024
+.Dt LPOSIX 3lua
+.Os
+.Sh NAME
+.Nm posix.fnmatch ,
+.Nm posix.libgen ,
+.Nm posix.stdlib ,
+.Nm posix.sys.stat ,
+.Nm posix.sys.utsname ,
+.Nm posix.sys.wait ,
+.Nm posix.unistd
+.Nd Lua POSIX interface module
+.Sh DESCRIPTION
+The
+.Nm lposix
+module provides POSIX system call bindings for Lua programs.
+.Ss Modules Available
+.Bl -tag -width indent
+.It Va posix.fnmatch
+Pattern matching functions.
+.Bl -bullet -compact
+.It
+fnmatch(pattern, string, flags)
+.El
+.It Va posix.libgen
+Path name operations.
+.Bl -bullet -compact
+.It
+basename(path)
+.It
+dirname(path)
+.El
+.It Va posix.stdlib
+Standard library functions.
+.Bl -bullet -compact
+.It
+_exit(status)
+.It
+realpath(path)
+.El
+.It Va posix.sys.stat
+File status operations.
+.Bl -bullet -compact
+.It
+chmod(path, mode)
+.It
+chown(path, uid, gid)
+.El
+.It Va posix.sys.utsname
+System name information.
+.Bl -bullet -compact
+.It
+uname()
+.El
+.It Va posix.sys.wait
+Process wait operations.
+.Bl -bullet -compact
+.It
+wait()
+.El
+.It Va posix.unistd
+POSIX operating system API.
+.Bl -bullet -compact
+.It
+fork()
+.It
+getpid()
+.It
+pipe()
+.It
+read(fd, count)
+.It
+write(fd, data)
+.El
+.El
+.Sh EXAMPLES
+Get system information:
+.Bd -literal -offset indent
+local posix = require "posix"
+local info = posix.sys.utsname.uname()
+print(info.sysname, info.release)
+.Ed
+.Pp
+Create a child process:
+.Bd -literal -offset indent
+local pid = posix.unistd.fork()
+if pid == 0 then
+ -- child process
+ posix.stdlib._exit(0)
+else
+ -- parent process
+ posix.sys.wait.wait()
+end
+.Ed
+.Sh SEE ALSO
+.Xr lua 1 ,
+.Xr luaopen_posix 3
+.Sh AUTHORS
+The
+.Nm
+man page was written by
+.An FreeBSD
diff --git a/share/examples/flua/fbsd_example.lua b/share/examples/flua/fbsd_example.lua
new file mode 100644
--- /dev/null
+++ b/share/examples/flua/fbsd_example.lua
@@ -0,0 +1,10 @@
+#!/usr/bin/env lua
+
+-- Example using the FreeBSD-specific module
+local fbsd = require "fbsd"
+
+print("Running 'ls -l' using fbsd.exec:")
+-- This will replace the current process
+fbsd.exec("/bin/ls", {"-l"})
+
+-- Note: Code after exec() won't be reached as the process is replaced
diff --git a/share/examples/flua/fetch_example.lua b/share/examples/flua/fetch_example.lua
new file mode 100644
--- /dev/null
+++ b/share/examples/flua/fetch_example.lua
@@ -0,0 +1,17 @@
+#!/usr/bin/env lua
+
+-- Example using the fetch module to download content
+local fetch = require "fetch"
+
+-- GET request example
+local response = fetch.get_url("https://www.freebsd.org")
+if response then
+ print("Fetched FreeBSD homepage, size:", #response)
+end
+
+-- POST request example
+local data = "key=value"
+local response = fetch.post_url("https://httpbin.org/post", data)
+if response then
+ print("POST response:", response)
+end
diff --git a/share/examples/flua/hash_example.lua b/share/examples/flua/hash_example.lua
new file mode 100644
--- /dev/null
+++ b/share/examples/flua/hash_example.lua
@@ -0,0 +1,18 @@
+#!/usr/bin/env lua
+
+-- Example using the hash module for SHA256
+local hash = require "hash"
+
+-- Create a new SHA256 hash
+local h = hash.sha256.new()
+
+-- Update with some data
+h:update("Hello, ")
+h:update("World!")
+
+-- Get the hex digest
+print("SHA256:", h:hexdigest())
+
+-- Show digest and block sizes
+print("Digest size:", hash.sha256.digest_size, "bytes")
+print("Block size:", hash.sha256.block_size, "bytes")
diff --git a/share/examples/flua/lfs_example.lua b/share/examples/flua/lfs_example.lua
new file mode 100644
--- /dev/null
+++ b/share/examples/flua/lfs_example.lua
@@ -0,0 +1,28 @@
+#!/usr/bin/env lua
+
+-- Example using the Lua FileSystem module
+local lfs = require "lfs"
+
+-- Directory listing
+print("Directory contents:")
+for file in lfs.dir(".") do
+ if file ~= "." and file ~= ".." then
+ local attrs = lfs.attributes(file)
+ print(string.format("%s: %d bytes (%s)",
+ file, attrs.size, attrs.mode))
+ end
+end
+
+-- Create and remove a directory
+local test_dir = "test_dir"
+lfs.mkdir(test_dir)
+print("\nCreated directory:", test_dir)
+lfs.rmdir(test_dir)
+print("Removed directory:", test_dir)
+
+-- File attributes
+local attr = lfs.attributes("/etc/passwd")
+print("\nFile attributes for /etc/passwd:")
+for name, value in pairs(attr) do
+ print(name, value)
+end
diff --git a/share/examples/flua/posix_example.lua b/share/examples/flua/posix_example.lua
new file mode 100644
--- /dev/null
+++ b/share/examples/flua/posix_example.lua
@@ -0,0 +1,31 @@
+#!/usr/bin/env lua
+
+-- Example using the POSIX module
+local posix = require "posix"
+
+-- System information
+local info = posix.sys.utsname.uname()
+print("System Information:")
+print("OS:", info.sysname)
+print("Release:", info.release)
+print("Version:", info.version)
+print("Machine:", info.machine)
+
+-- File operations
+print("\nFile operations:")
+local path = "test.txt"
+local fd = posix.unistd.open(path, posix.fcntl.O_WRONLY + posix.fcntl.O_CREAT, "644")
+posix.unistd.write(fd, "Hello from Lua POSIX!\n")
+posix.unistd.close(fd)
+print("Created file:", path)
+
+-- Process operations
+print("\nProcess information:")
+print("PID:", posix.unistd.getpid())
+print("Parent PID:", posix.unistd.getppid())
+
+-- Pattern matching
+print("\nPattern matching:")
+local pattern = "*.lua"
+local match = posix.fnmatch.fnmatch(pattern, "test.lua", 0)
+print(string.format("'test.lua' matches '%s': %s", pattern, match and "yes" or "no"))
diff --git a/share/examples/flua/ucl_example.lua b/share/examples/flua/ucl_example.lua
new file mode 100644
--- /dev/null
+++ b/share/examples/flua/ucl_example.lua
@@ -0,0 +1,46 @@
+#!/usr/bin/env lua
+
+-- Example using the UCL module
+local ucl = require "ucl"
+
+-- Create a new parser
+local parser = ucl.parser_new()
+
+-- Add some UCL configuration data
+local config = [[
+# Server configuration
+server {
+ host = "localhost";
+ port = 8080;
+
+ # Array of allowed origins
+ origins [
+ "https://example.com",
+ "https://test.com"
+ ];
+
+ # Nested object
+ ssl {
+ enabled = true;
+ cert = "/path/to/cert.pem";
+ }
+}
+]]
+
+-- Parse the configuration
+parser:add_chunk(config)
+
+-- Get the resulting object
+local obj = parser:get_object()
+
+-- Access the parsed data
+print("Server Configuration:")
+print("Host:", obj.server.host)
+print("Port:", obj.server.port)
+print("\nAllowed Origins:")
+for _, origin in ipairs(obj.server.origins) do
+ print("-", origin)
+end
+print("\nSSL Settings:")
+print("Enabled:", obj.server.ssl.enabled)
+print("Certificate:", obj.server.ssl.cert)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Aug 21, 7:21 PM (14 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37026731
Default Alt Text
D57660.id180054.diff (11 KB)
Attached To
Mode
D57660: flua: add missing manpages and some helpful examples
Attached
Detach File
Event Timeline
Log In to Comment