Skip to content

Commit

Permalink
Further cosmetics fixes to Lua docs
Browse files Browse the repository at this point in the history
Use single quotes consistently, use back-quotes where appropriate.
Add the odd missing quote.
  • Loading branch information
pmatilai committed Oct 18, 2021
1 parent c42a421 commit 4474ed1
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions docs/manual/lua.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The internal Lua can be used as the interpreter of rpm any scriptlets (%pre, %po

```
%pre -p <lua>
print("Hello from Lua")
print('Hello from Lua')
```

The point? Remember, Lua is embedded in rpm. This means the Lua scriptlets run in the rpm process context, instead of forking a new process to execute something. This has a number of advantages over, say, using /bin/sh as scriptlet interpreter:
Expand All @@ -33,19 +33,19 @@ While scriptlets shouldn't be allowed to fail normally, you can signal scriptlet
The internal Lua interpreter can be used for dynamic macro content creation:

```
%{lua: print("Requires: foo >= 1.2")}
%{lua: print('Requires: foo >= 1.2')}
```

The above is a silly example and doesn't even begin to show how powerful a feature this is. For a slightly more complex example, RPM itself uses this to implement %patches and %sources macros (new in RPM 4.6.0):

```
%patches %{lua: for i, p in ipairs(patches) do print(p.." ") end}
%sources %{lua: for i, s in ipairs(sources) do print(s.." ") end}
%patches %{lua: for i, p in ipairs(patches) do print(p..' ') end}
%sources %{lua: for i, s in ipairs(sources) do print(s..' ') end}
```

Parametric Lua macros receive their options and arguments as two local
tables "opt" and "arg", where "opt" holds processed option values keyed by
the option character, and "arg" contains arguments numerically indexed.
tables `opt` and `arg`, where `opt` holds processed option values keyed by
the option character, and `arg` contains arguments numerically indexed.
These tables are always present regardless of whether options or arguments
were actually passed to simplify use. (rpm >= 4.17)

Expand Down Expand Up @@ -118,7 +118,7 @@ and any previous definitions of the same name remain underneath after
a define.

```
rpm.define("foo 1")
rpm.define('foo 1')
```

See also `undefine()`
Expand All @@ -139,8 +139,8 @@ rpm.execute('ls', '-l', '/')
Perform rpm macro expansion on argument string.

```
rpm.expand("/usr%{__lib}/mypath")
rpm.expand("%{_libdir}")
rpm.expand('/usr%{__lib}/mypath')
rpm.expand('%{_libdir}')
```

#### interactive()
Expand All @@ -156,7 +156,7 @@ rpm --eval "%{lua: rpm.interactive()}"
Test whether a macro is defined and whether it's parametric, returned in two booleans (rpm >= 4.17.0)

```
if rpm.isdefined("_libdir") then
if rpm.isdefined('_libdir') then
...
end
```
Expand Down Expand Up @@ -282,7 +282,7 @@ this was known as posix.redirect2null())
pid = posix.fork()
if pid == 0 then
posix.redirect2null(2)
assert(posix.exec("/bin/awk"))
assert(posix.exec('/bin/awk'))
elseif pid > 0 then
posix.wait(pid)
end
Expand All @@ -307,7 +307,7 @@ Perform RPM version comparison on argument strings (rpm >= 4.7.0).
Returns -1, 0 or 1 if `v1` is smaller, equal or larger than `v2`.

```
rpm.vercmp("1.2-1", "2.0-1")
rpm.vercmp('1.2-1', '2.0-1')
```

Note that in rpm < 4.16 this operated on version segments only, which
Expand Down Expand Up @@ -338,7 +338,7 @@ end

Lua standard library offers fairly limited set of io operations.
The posix extension greatly enhances what can be done from Lua.
The following functions are available in "posix" namespace, ie to call
The following functions are available in `posix` namespace, ie to call
them use posix.function(). This documentation concentrates on the Lua
API conventions, for further information on the corresponding system
calls refer to the system manual, eg `man 3 access` for `posix.access()`.
Expand All @@ -357,7 +357,7 @@ tested, otherwise it is a combination of the following tests:
| f | Existence

```
if posix.access("/bin/rpm", "x") then
if posix.access('/bin/rpm', 'x') then
...
end
```
Expand All @@ -367,7 +367,7 @@ end
Change current working directory.

```
posix.chdir("/tmp")
posix.chdir('/tmp')
```

#### chmod(path, mode)
Expand Down Expand Up @@ -405,8 +405,8 @@ Get directory contents - like readdir(). If path is omitted, current
directory is used.

```
for i,p in pairs(posix.dir("/")) do
print(p.."\n")
for i,p in pairs(posix.dir('/')) do
print(p..'\n')
end
```

Expand All @@ -432,7 +432,7 @@ Iterate over directory contents. If path is omitted, current directory
is used.

```
for f in posix.files("/") do
for f in posix.files('/') do
print(f..'\n')
end
```
Expand All @@ -445,7 +445,7 @@ For executing external commands it's recommended to use `rpm.execute()` instead.
```
pid = posix.fork()
if pid == 0 then
posix.exec("/foo/bar")
posix.exec('/foo/bar')
elseif pid > 0 then
posix.wait(pid)
end
Expand Down Expand Up @@ -498,7 +498,7 @@ one of `name`, `uid`, `gid`, `dir`, `shell`, `gecos` and `passwd` and if
omitted, a table with all these fields is returned.

```
pw = posix.getpasswd(posix.getlogin(), "shell")|
pw = posix.getpasswd(posix.getlogin(), 'shell')|
```

#### getprocessid([selector])
Expand Down Expand Up @@ -581,7 +581,7 @@ print(posix.readlink('bbb'))
Remove a directory

```
posix.rmdir("/tmp")|
posix.rmdir('/tmp')
```

#### setgid(group)
Expand Down Expand Up @@ -640,7 +640,7 @@ Get `sysconf(3)` information. The optional selector may be one of
with all these fields is returned.

```
posix.sysconf("open_max")|
posix.sysconf('open_max')|
```

#### times([selector])
Expand Down Expand Up @@ -673,7 +673,7 @@ mode string similarly to posix.chmod().
```
print(posix.umask())
posix.umask(222)
posix.umask('ug-w)
posix.umask('ug-w')
posix.umask('rw-rw-r--')
```

Expand All @@ -691,7 +691,7 @@ supported:
| %v | Current version level of this implementation

```
print(posix.uname("%r"))
print(posix.uname('%r'))
```

#### utime(path [, mtime] [, ctime])
Expand All @@ -712,7 +712,7 @@ Wait for a child process. If pid is specified wait for that particular child.
```
pid = posix.fork()
if pid == 0 then
posix.exec("/bin/ls"))
posix.exec('/bin/ls'))
elseif pid > 0 then
posix.wait(pid)
end
Expand Down

0 comments on commit 4474ed1

Please sign in to comment.