Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
apk-tools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
59
Issues
59
List
Boards
Labels
Service Desk
Milestones
Merge Requests
13
Merge Requests
13
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpine
apk-tools
Commits
391cd01b
Commit
391cd01b
authored
Feb 21, 2011
by
Natanael Copa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lua: implement iterator with installed packages
parent
9e60a72b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
5 deletions
+43
-5
src/lua-apk.c
src/lua-apk.c
+43
-5
No files found.
src/lua-apk.c
View file @
391cd01b
...
...
@@ -9,7 +9,8 @@
#include "apk_version.h"
#define LIBNAME "apk"
#define APKDB_META "apk_database"
#define APK_DB_META "apk_database"
#define APK_IPKG_META "apk_installed_package"
struct
flagmap
{
const
char
*
name
;
...
...
@@ -134,9 +135,9 @@ static struct apk_database *checkdb(lua_State *L, int index)
{
struct
apk_database
*
db
;
luaL_checktype
(
L
,
index
,
LUA_TUSERDATA
);
db
=
(
struct
apk_database
*
)
luaL_checkudata
(
L
,
index
,
APKDB_META
);
db
=
(
struct
apk_database
*
)
luaL_checkudata
(
L
,
index
,
APK
_
DB_META
);
if
(
db
==
NULL
)
luaL_typerror
(
L
,
index
,
APKDB_META
);
luaL_typerror
(
L
,
index
,
APK
_
DB_META
);
return
db
;
}
...
...
@@ -155,7 +156,7 @@ static int Papk_db_open(lua_State *L)
opts
.
open_flags
|=
APK_OPENF_READ
;
db
=
lua_newuserdata
(
L
,
sizeof
(
struct
apk_database
));
luaL_getmetatable
(
L
,
APKDB_META
);
luaL_getmetatable
(
L
,
APK
_
DB_META
);
lua_setmetatable
(
L
,
-
2
);
r
=
apk_db_open
(
db
,
&
opts
);
...
...
@@ -227,6 +228,42 @@ ret_nil:
return
1
;
}
// Iterator of all installed packages
struct
apk_installed_package_iterator
{
struct
list_head
*
end
;
struct
apk_installed_package
*
node
;
};
static
int
iterate_installed
(
lua_State
*
L
)
{
struct
apk_installed_package_iterator
*
i
;
struct
apk_installed_package
*
ipkg
;
i
=
(
struct
apk_installed_package_iterator
*
)
lua_touserdata
(
L
,
lua_upvalueindex
(
1
));
ipkg
=
i
->
node
;
if
(
&
ipkg
->
installed_pkgs_list
==
i
->
end
)
return
0
;
i
->
node
=
list_entry
(
ipkg
->
installed_pkgs_list
.
next
,
typeof
(
*
ipkg
),
installed_pkgs_list
);
return
push_package
(
L
,
ipkg
->
pkg
);
}
static
int
Pinstalled
(
lua_State
*
L
)
{
struct
apk_database
*
db
=
checkdb
(
L
,
1
);
struct
apk_installed_package_iterator
*
i
;
i
=
(
struct
apk_installed_package_iterator
*
)
lua_newuserdata
(
L
,
sizeof
(
*
i
));
i
->
end
=
&
db
->
installed
.
packages
;
i
->
node
=
list_entry
((
&
db
->
installed
.
packages
)
->
next
,
struct
apk_installed_package
,
installed_pkgs_list
);
lua_pushcclosure
(
L
,
iterate_installed
,
1
);
return
1
;
}
static
const
luaL_reg
reg_apk_methods
[]
=
{
{
"version_validate"
,
Pversion_validate
},
{
"version_compare"
,
Pversion_compare
},
...
...
@@ -235,6 +272,7 @@ static const luaL_reg reg_apk_methods[] = {
{
"who_owns"
,
Papk_who_owns
},
{
"exists"
,
Papk_exists
},
{
"is_installed"
,
Papk_exists
},
{
"installed"
,
Pinstalled
},
{
NULL
,
NULL
}
};
...
...
@@ -250,7 +288,7 @@ LUALIB_API int luaopen_apk(lua_State *L)
lua_pushliteral
(
L
,
APK_VERSION
);
lua_settable
(
L
,
-
3
);
luaL_newmetatable
(
L
,
APKDB_META
);
luaL_newmetatable
(
L
,
APK
_
DB_META
);
luaL_register
(
L
,
NULL
,
reg_apk_db_meta_methods
);
lua_pushliteral
(
L
,
"__index"
);
lua_pushvalue
(
L
,
-
3
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment