libtoml fork that uses tlibc
Go to file
2025-11-27 01:45:05 +05:00
.vscode moved functions code to separate files 2025-11-26 16:26:01 +05:00
dependencies replaced TomlString with StringBuilder 2025-11-10 05:42:29 +05:00
include changed TomlValue.value to anonymous union 2025-11-27 01:32:34 +05:00
src changed TomlValue.value to anonymous union 2025-11-27 01:32:34 +05:00
tests changed TomlValue.value to anonymous union 2025-11-27 01:32:34 +05:00
.gitignore project created 2025-11-09 23:47:51 +05:00
project.config added tlibc error handling everywhere 2025-11-26 16:42:40 +05:00
project.config.user.default project created 2025-11-09 23:47:51 +05:00
README.md updated README.md 2025-11-27 01:45:05 +05:00
tlibtoml.config fixed DEPENDENCIES_DIR bug in tlibtoml.config 2025-11-27 01:25:35 +05:00

tlibtoml

A fork of libtoml rewritten to use tlibc instead of its own (worse) implementation of collections and strings. For example, Table from libtoml is just an array of key-value pairs, where search happens by calling strcmp() on each element. Such inefficient code hurts my mind, so i have no other choise than to rewrite this library.

Build

  1. Clone this repository.

    git clone https://timerix.ddns.net/git/Timerix/tlibtoml.git
    
  2. Install cbuild. Select latest version compatible with the one in project.config. Example: For 2.3.0 download latest 2.3.x.

  3. Clone tlibc. By default dependencies/tlibc.config expects that tlibc/ is present in the same directory as tlibtoml/. If you cloned it to another directory, change DEPENDENCIES_DIR in tlibtoml/project.user.config.

    git clone https://timerix.ddns.net/git/Timerix/tlibc.git
    
  4. Build and run tests

    cd tlibtoml
    cbuild build_exec exec
    
  5. To build library use tasks build_static_lib[_dbg] or build_shared_lib[_dbg]

Usage

#include "tlibtoml.h"

int main(){
    Deferral(32); // reserve memory for 32 defers
    // init tlibc global variables
    try_fatal_void(tlibc_init());
    // init tlibtoml global variables
    try_fatal_void(tlibtoml_init());
    Defer(tlibc_deinit());
    Defer(tlibtoml_deinit());

    // load whole file to memory and parse it as toml
    try_fatal(TomlTable* t, p, toml_load_filename("example.toml"));
    // get value by key and ensure it's a string
    try_fatal(str* s, p, TomlTable_get_str(t, STR("some_key")));
    // print this string value
    printf("some_key = '"FMT_str"'\n", str_expand(*s));

    Return 0; // call defers
}