]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Add lua to bindings documentation
authorMichael Schroeder <mls@suse.de>
Mon, 25 Mar 2024 12:03:01 +0000 (13:03 +0100)
committerMichael Schroeder <mls@suse.de>
Mon, 25 Mar 2024 12:03:01 +0000 (13:03 +0100)
doc/gen/libsolv-bindings.3
doc/gen/libsolv-pool.3
doc/gen/testsolv.1
doc/libsolv-bindings.txt

index 2970a79063ddad318d47b2fbd057d35211baeb9f..29e95a78e8ac947a9ac968b509202a1747c58150 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: Libsolv-Bindings
 .\"    Author: [see the "Author" section]
 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
-.\"      Date: 01/31/2023
+.\"      Date: 03/25/2024
 .\"    Manual: LIBSOLV
 .\"    Source: libsolv
 .\"  Language: English
 .\"
-.TH "LIBSOLV\-BINDINGS" "3" "01/31/2023" "libsolv" "LIBSOLV"
+.TH "LIBSOLV\-BINDINGS" "3" "03/25/2024" "libsolv" "LIBSOLV"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -391,7 +391,9 @@ Stringification is done by calling the object\(cqs \(lqstr\(rq method\&.
 .RE
 .\}
 .sp
-There is one exception: you have to use \(lqstringify\(rq for Datamatch objects, as swig reports a clash with the \(lqstr\(rq attribute\&. Some objects also support a \(lq==\(rq method for equality tests, and a \(lq!=\(rq method\&.
+There is one exception: you have to use \(lqstringify\(rq for Datamatch objects, as swig reports a clash with the \(lqstr\(rq attribute\&.
+.sp
+Some classes also support a \(lq==\(rq method for equality tests, and a \(lq!=\(rq method\&.
 .sp
 Swig implements all constants as numeric variables, constants belonging to a libsolv class are prefixed with the class name:
 .sp
@@ -405,6 +407,122 @@ Swig implements all constants as numeric variables, constants belonging to a lib
 .if n \{\
 .RE
 .\}
+.sp
+Iterators also work as expected:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fBfor\fR \fIsolvable\fR \fBin\fR \fIpool\fR\fB\&.solvables_iter() do \&.\&.\&.\fR
+.fi
+.if n \{\
+.RE
+.\}
+.SH "LUA SPECIFICS"
+.sp
+Libsolv\(cqs lua bindings can be loaded with the following statement:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fBrequire("solv")\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+Objects are either created by calling the constructor method for a class or they are returned by calling methods on other objects\&.
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fIpool\fR \fB= solv\&.Pool()\fR
+\fIrepo\fR \fB=\fR \fIpool\fR\fB:add_repo("my_first_repo")\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+Note the \(lq:method\(rq syntax that makes lua add the object as first argument\&.
+.sp
+Attributes can be accessed as usual:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fIpool\fR\fB\&.appdata = 42\fR
+\fBprint("appdata is "\&.\&.pool\&.appdata)\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+Iterators also work as expected:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fBfor\fR \fIsolvable\fR \fBin\fR \fIpool\fR\fB\&.solvables do \&.\&.\&.\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+Note that some functions return a table instead of an iterator, so you need to use \(lqipairs\(rq for iteration:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fBfor\fR \fI_\fR\fB,solvable\fR \fBin ipairs(\fR\fIjob\fR\fB\&.solvables()) do \&.\&.\&.\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+Arrays are passed and returned as tables:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fIjobs\fR \fB= {}\fR
+\fIproblems\fR \fB=\fR \fIsolver\fR\fB\&.solve(\fR\fIjobs\fR\fB)\fR
+\fBif #problems != 0 then \&.\&.\&.\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+The bindings define a \(lq__tostring\(rq method for many classes:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fBprint(\fR\fIdep\fR\fB)\fR
+\fBprint(("Package: %\fR\fIs\fR\fB"):format(\fR\fIsolvable\fR\fB))\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+Constants live in the namespace of the class they belong to:
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fIpool\fR\fB:set_flag(Solv\&.Pool\&.POOL_FLAG_OBSOLETEUSESCOLORS, 1)\fR;
+.fi
+.if n \{\
+.RE
+.\}
 .SH "THE SOLV CLASS"
 .sp
 This is the main namespace of the library, you cannot create objects of this type but it contains some useful constants\&.
@@ -3609,7 +3727,7 @@ Update the matching installed packages to their best version\&. If none of the s
 .PP
 \fBSOLVER_WEAKENDEPS\fR
 .RS 4
-Allow breaking the dependencies of the matching packages\&. Handle with care\&.
+Allow one to break the dependencies of the matching packages\&. Handle with care\&.
 .RE
 .PP
 \fBSOLVER_MULTIVERSION\fR
index 1e2bfb8f78abb246d2fd7b2a4f647fd438307c5d..52ae62686f213b2c7e3619c27faf183afa5792ca 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: Libsolv-Pool
 .\"    Author: [see the "Author" section]
 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
-.\"      Date: 03/02/2022
+.\"      Date: 03/25/2024
 .\"    Manual: LIBSOLV
 .\"    Source: libsolv
 .\"  Language: English
 .\"
-.TH "LIBSOLV\-POOL" "3" "03/02/2022" "libsolv" "LIBSOLV"
+.TH "LIBSOLV\-POOL" "3" "03/25/2024" "libsolv" "LIBSOLV"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index 0a5b9697f7c6f21329ce77df0bf046e7be16587c..b487f27cb108e09a061fc53ac5322461efdf5ef6 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: testsolv
 .\"    Author: [see the "Author" section]
 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
-.\"      Date: 09/14/2018
+.\"      Date: 03/25/2024
 .\"    Manual: LIBSOLV
 .\"    Source: libsolv
 .\"  Language: English
 .\"
-.TH "TESTSOLV" "1" "09/14/2018" "libsolv" "LIBSOLV"
+.TH "TESTSOLV" "1" "03/25/2024" "libsolv" "LIBSOLV"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index a1dee398967b7f8e48d8c57123fabf5eefa7b5ae..53b62eb83c8e1f7b140dbe6f04deedae0a1774e1 100644 (file)
@@ -177,7 +177,8 @@ Stringification is done by calling the object's ``str'' method.
 
 There is one exception: you have to use ``stringify'' for Datamatch
 objects, as swig reports a clash with the ``str'' attribute.
-Some objects also support a ``=='' method for equality tests, and a
+
+Some classes also support a ``=='' method for equality tests, and a
 ``!='' method.
 
 Swig implements all constants as numeric variables, constants belonging
@@ -186,6 +187,53 @@ to a libsolv class are prefixed with the class name:
        TCL $pool set_flag $solv::Pool_POOL_FLAG_OBSOLETEUSESCOLORS 1
        TCL puts [$solvable lookup_str $solv::SOLVABLE_SUMMARY]
 
+Iterators also work as expected:
+
+       for solvable in pool.solvables_iter() do ...
+
+Lua Specifics
+-------------
+Libsolv's lua bindings can be loaded with the following statement:
+
+       require("solv")
+
+Objects are either created by calling the constructor method for a class or they
+are returned by calling methods on other objects.
+
+       pool = solv.Pool()
+       repo = pool:add_repo("my_first_repo")
+
+Note the ``:method'' syntax that makes lua add the object as first argument.
+
+Attributes can be accessed as usual:
+
+       pool.appdata = 42
+       print("appdata is "..pool.appdata)
+
+Iterators also work as expected:
+
+       for solvable in pool.solvables do ...
+
+Note that some functions return a table instead of an iterator, so you
+need to use ``ipairs'' for iteration:
+
+       for _,solvable in ipairs(job.solvables()) do ...
+
+Arrays are passed and returned as tables:
+
+       jobs = {}
+       problems = solver.solve(jobs)
+       if #problems != 0 then ...
+
+The bindings define a ``__tostring'' method for many classes:
+
+       print(dep)
+       print(("Package: %s"):format(solvable))
+
+Constants live in the namespace of the class they belong to:
+
+       pool:set_flag(Solv.Pool.POOL_FLAG_OBSOLETEUSESCOLORS, 1);
+
 
 The Solv Class
 --------------