diff --git a/doc/gen/libsolv-bindings.3 b/doc/gen/libsolv-bindings.3 index 2970a7906..29e95a78e 100644 --- a/doc/gen/libsolv-bindings.3 +++ b/doc/gen/libsolv-bindings.3 @@ -2,12 +2,12 @@ .\" Title: Libsolv-Bindings .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets vsnapshot -.\" 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 diff --git a/doc/gen/libsolv-pool.3 b/doc/gen/libsolv-pool.3 index 1e2bfb8f7..52ae62686 100644 --- a/doc/gen/libsolv-pool.3 +++ b/doc/gen/libsolv-pool.3 @@ -2,12 +2,12 @@ .\" Title: Libsolv-Pool .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets vsnapshot -.\" 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 .\" ----------------------------------------------------------------- diff --git a/doc/gen/testsolv.1 b/doc/gen/testsolv.1 index 0a5b9697f..b487f27cb 100644 --- a/doc/gen/testsolv.1 +++ b/doc/gen/testsolv.1 @@ -2,12 +2,12 @@ .\" Title: testsolv .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets vsnapshot -.\" 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 .\" ----------------------------------------------------------------- diff --git a/doc/libsolv-bindings.txt b/doc/libsolv-bindings.txt index a1dee3989..53b62eb83 100644 --- a/doc/libsolv-bindings.txt +++ b/doc/libsolv-bindings.txt @@ -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 --------------