mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Added example to doc.
This commit is contained in:
@@ -292,7 +292,46 @@ This documentation is a work in progress, covering an API that is also still a w
|
||||
</div>
|
||||
|
||||
<h2 id="examples">Examples</h2>
|
||||
<p>The <code>api-tester</code> application provides a very simple usage example. Its source code is hosted with the BOSS API source code.
|
||||
<p>The following is a short program that will print out a list of dirty messages for a given plugin.
|
||||
<code class="box">#include "api.h"
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
boss_db db;
|
||||
unsigned int ret;
|
||||
boss_message * messages;
|
||||
size_t numMessages;
|
||||
|
||||
if (argc != 2) {
|
||||
std::cout << "Invalid args.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Creating a database for Oblivion, using path stored in Registry.
|
||||
ret = boss_create_db(&db, BOSS_API_GAME_TES4, NULL);
|
||||
|
||||
//Load a masterlist that's in the current working directory.
|
||||
ret = boss_load_lists(db, "masterlist.yaml", NULL);
|
||||
|
||||
//We only want the messages that are relevant to the current install.
|
||||
ret = boss_eval_lists(db);
|
||||
|
||||
//Now fetch the messages for the plugin given as the program's argument.
|
||||
ret = boss_get_plugin_messages(db, argv[1], &messages, &numMessages);
|
||||
|
||||
//Dirty messages are of the warning type and contain the substring "dirty edits".
|
||||
for (size_t i = 0; i < numMessages; ++i) {
|
||||
if (messages[i].type == BOSS_API_MESSAGE_WARN &&
|
||||
strstr(messages[i].message, "dirty edits") != NULL) {
|
||||
std::cout << messages[i].message << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
</code>
|
||||
|
||||
<h2 id="credits">Credits</h2>
|
||||
<p>Thanks go to Lojack and myk002 for significant contributions during planning and beta testing, and to kaburke for beta testing of v2 of the API.
|
||||
|
||||
@@ -291,9 +291,6 @@ namespace boss {
|
||||
// Condition parser/evaluator
|
||||
///////////////////////////////
|
||||
|
||||
/* Still need to add support for bracketing and evaluation of the compound
|
||||
conditions. */
|
||||
|
||||
namespace qi = boost::spirit::qi;
|
||||
namespace unicode = boost::spirit::unicode;
|
||||
namespace phoenix = boost::phoenix;
|
||||
|
||||
Reference in New Issue
Block a user