ZZ Project API
Add this to zz.toml:
[dependencies] project = "*" [repos] project = "git://github.com/zzmodules/project"using project fn main() -> int{new+1024 mut error = err::make(); new mut proj = project::current(); bool status = proj.open(&error); if error.check(){log::error("%s", error.trace.cstr())} // read all dependencies let mut it = proj.config.dependencies.iterator(); while !it.ended{let node = it.next(); let dep = as<project::ProjectDependency *>(node->value); log::info("%s = %s", dep->name.cstr(), dep->version.cstr())} return0}A structure that represents a ZZ project. When opened, the project's zz.toml file is parsed and its values are loaded.
structProject{Path path; ProjectConfig config}A structure that represents the configuration for a project, as seen in a zz.toml file.
structProjectConfig{String+32 mut version; String+64 mut name; String+64000 mut description; List+64 mut cincludes; List+64 mut cobjects; List+64 mut pkgconfig; List+64 mut cflags; List+64 mut lflags; List+64 mut dependencies; List+64 mut repos}A structure that represents a project dependency repository.
structProjectRepository{String+64 mut name; String+1024 mut url}A structure that represents a project dependency.
structProjectDependency{String+32 mut version; String+64 mut name}Project constructor that gets the default project based on the callsite of this function.
new mut proj = project::current();Project structure constructor.
new mut proj = project::make(&pathname);Opens the project, parsing the "zz.toml" values into memory. This function returns true upon success, or false if an error occurs. The error given to this function should be checked.
new+1024 mut error = err::make(); bool status = proj.open(&error);Accessor for the project's name.
log::info("%s", proj.name());Accessor for the project's version.
log::info("%s", proj.version());Accessor for the project's description.
log::info("%s", proj.description());Accessor for the project's cincludes as a list iterator.
let mut cincludes = proj.cincludes(); while !cincludes.ended{let cinclude = as<char *>(cincludes.next()->value); log::info("%s", cinclude)}Accessor for the project's cobjects as a list iterator.
let mut cobjects = proj.cobjects(); while !cobjects.ended{let cinclude = as<char *>(cobjects.next()->value); log::info("%s", cinclude)}Accessor for the project's pkgconfig as a list iterator.
let mut pkgconfig = proj.pkgconfig(); while !pkgconfig.ended{let cinclude = as<char *>(pkgconfig.next()->value); log::info("%s", cinclude)}Accessor for the project's cflags as a list iterator.
let mut cflags = proj.cflags(); while !cflags.ended{let cinclude = as<char *>(cflags.next()->value); log::info("%s", cinclude)}Accessor for the project's lflags as a list iterator.
let mut lflags = proj.lflags(); while !lflags.ended{let cinclude = as<char *>(lflags.next()->value); log::info("%s", cinclude)}Accessor for the project's dependencies as a list iterator.
let mut dependencies = proj.config.dependencies.iterator(); while !dependencies.ended{let dependency = as<ProjectDependency *>(dependencies.next()->value); log::info("%s = %s", dependency->name.cstr(), dependency->version.cstr())}Accessor for the project's repos as a list iterator.
let mut repos = proj.config.repos.iterator(); while !repos.ended{let repo = as<ProjectRepository *>(repos.next()->value); log::info("%s = %s", repo->name.cstr(), repo->url.cstr())}A custom iterator function for the TOML parser can be supplied to handle sections in the zz.toml file not handled by the default toml_parser_document_iterator() function.
using err using path using project using toml using string fn main() -> int{new+1024 mut error = err::make(); new project_path = path::canonicalize("./"); new mut proj = project::make(&project_path.string); proj.custom.toml_parser_document_iterator = toml_parser_document_iterator; if !proj.open(&error){if error.check(){log::error("%s", error.trace.cstr())} } return0} fn toml_parser_document_iterator( toml::U *self, Err+ErrorTail mut *error, toml::Parser+ParserTail mut *parser, char *key, toml::Value value ) where err::checked(*error){static_attest(safe(key)); static_attest(nullterm(key)); let mut *project = as<Project mut *>(self->user1); if error->check(){return} // handle a custom section...ifutils::compare_string("custom-section", key){toml::next(parser, error, toml::U{it: toml_parser_custom_section_iterator, user1: project })} } fn toml_parser_custom_section_iterator( toml::U *self, Err+ErrorTail mut *error, toml::Parser+ParserTail mut *parser, char *key, toml::Value value ) where err::checked(*error){static_attest(safe(key)); static_attest(nullterm(key)); let mut *project = as<Project mut *>(self->user1); if error->check(){return} // handle custom section keys... }Custom TOML & JSON output can be achieved by implementing a to_toml(project, output) and to_json(project, output) functions which are called when project::to_toml() or project::to_json() is called.
using err using toml using string using project fn main() -> int{new+1024 mut error = err::make(); new+1024 mut path = string::from("./"); new mut proj = project::make(&path); proj.custom.to_toml = custom_to_toml; proj.custom.to_json = custom_to_json; if !proj.open(&error){if error.check(){log::error("%s", error.trace.cstr())} } return0} export fn to_toml(Project *self, String+OutputTail mut *output){// add custom sections to `output` } export fn to_json(Project *self, String+OutputTail mut *output){// add custom key-value pairs to `output` }MIT