Compare commits
4 Commits
bd38585b35
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cb121d1de | |||
| 559902eaf5 | |||
| 11f16a79fc | |||
| a15b5a6b32 |
@@ -1,5 +1,5 @@
|
|||||||
# tlibtoml
|
# tlibtoml
|
||||||
A fork of [libtoml](https://github.com/brglng/libtoml) rewritten to use [tlibc](https://timerix.ddns.net/git/Timerix/tlibtoml) 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.
|
A fork of [libtoml](https://github.com/brglng/libtoml) rewritten to use [tlibc](https://timerix.ddns.net/git/Timerix/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
|
## Build
|
||||||
@@ -27,6 +27,8 @@ A fork of [libtoml](https://github.com/brglng/libtoml) rewritten to use [tlibc](
|
|||||||
|
|
||||||
5. To build library use tasks `build_static_lib[_dbg]` or `build_shared_lib[_dbg]`
|
5. To build library use tasks `build_static_lib[_dbg]` or `build_shared_lib[_dbg]`
|
||||||
|
|
||||||
|
6. If you use tlibtoml as static library, add `LINKER_LIBS` from tlibtoml `project.config` to your project.
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
```c
|
```c
|
||||||
@@ -46,7 +48,7 @@ int main(){
|
|||||||
// get value by key and ensure it's a string
|
// get value by key and ensure it's a string
|
||||||
try_fatal(str* s, p, TomlTable_get_str(t, STR("some_key")));
|
try_fatal(str* s, p, TomlTable_get_str(t, STR("some_key")));
|
||||||
// print this string value
|
// print this string value
|
||||||
printf("some_key = '"FMT_str"'\n", str_expand(*s));
|
printf("some_key = '"FMT_str"'\n", str_unwrap(*s));
|
||||||
|
|
||||||
Return 0; // call defers
|
Return 0; // call defers
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ case "$OS" in
|
|||||||
EXEC_FILE="test.exe"
|
EXEC_FILE="test.exe"
|
||||||
SHARED_LIB_FILE="$PROJECT.dll"
|
SHARED_LIB_FILE="$PROJECT.dll"
|
||||||
INCLUDE="$INCLUDE "
|
INCLUDE="$INCLUDE "
|
||||||
# example: "-lSDL2 -lSDL2_image"
|
LINKER_LIBS="-luuid"
|
||||||
LINKER_LIBS=""
|
|
||||||
;;
|
;;
|
||||||
LINUX)
|
LINUX)
|
||||||
EXEC_FILE="test"
|
EXEC_FILE="test"
|
||||||
|
|||||||
@@ -15,6 +15,6 @@ void TomlArray_free(TomlArray* self)
|
|||||||
{
|
{
|
||||||
if(!self)
|
if(!self)
|
||||||
return;
|
return;
|
||||||
List_TomlValue_destroy(self);
|
List_TomlValue_destroyWithElements(self, TomlValue_destroy);
|
||||||
free(self);
|
free(self);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void TomlTable_free(TomlTable* self)
|
|||||||
Return RESULT_ERROR_CODE_FMT( \
|
Return RESULT_ERROR_CODE_FMT( \
|
||||||
TLIBTOML, TLIBTOML_ERR_NOT_FOUND, \
|
TLIBTOML, TLIBTOML_ERR_NOT_FOUND, \
|
||||||
"can't find '"FMT_str"'", \
|
"can't find '"FMT_str"'", \
|
||||||
str_expand(KEY)); \
|
str_unwrap(KEY)); \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
#define try_assert_value_type(VAL, KEY, TYPE) \
|
#define try_assert_value_type(VAL, KEY, TYPE) \
|
||||||
@@ -35,7 +35,7 @@ void TomlTable_free(TomlTable* self)
|
|||||||
Return RESULT_ERROR_CODE_FMT( \
|
Return RESULT_ERROR_CODE_FMT( \
|
||||||
TLIBTOML, TLIBTOML_ERR_UNEXPECTED_TYPE, \
|
TLIBTOML, TLIBTOML_ERR_UNEXPECTED_TYPE, \
|
||||||
"expected '"FMT_str"' of type '"FMT_str"', but got '"FMT_str"'", \
|
"expected '"FMT_str"' of type '"FMT_str"', but got '"FMT_str"'", \
|
||||||
str_expand(KEY), str_expand(t_expected_s), str_expand(t_got_s)); \
|
str_unwrap(KEY), str_unwrap(t_expected_s), str_unwrap(t_got_s)); \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
Result(TomlTable*) TomlTable_get_table(const TomlTable* self, str key)
|
Result(TomlTable*) TomlTable_get_table(const TomlTable* self, str key)
|
||||||
|
|||||||
Reference in New Issue
Block a user