mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-30 13:00:06 +00:00
[examples] hello_world.c first pass; parse check touch ups; API touch ups
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
** Example: hello world
|
||||
**
|
||||
**
|
||||
**
|
||||
*/
|
||||
|
||||
//~ Includes and globals //////////////////////////////////////////////////////
|
||||
|
||||
// @notes Metadesk is a source-include library. So we include the
|
||||
// file "md.c" into the usage code directly. The library
|
||||
|
||||
#include "md.h"
|
||||
#include "md.c"
|
||||
|
||||
// @notes For simple single-threaded memory management in a run-once-and-exit
|
||||
// utility, a single global arena is our prefered setup.
|
||||
static MD_Arena *arena = 0;
|
||||
|
||||
//~ main //////////////////////////////////////////////////////////////////////
|
||||
|
||||
int
|
||||
main(int argc, char **argv){
|
||||
// setup the global arena
|
||||
// @notes Metadesk arenas do linear reserve-and-commit allocation. This
|
||||
// code makes an arena with a 1 terabyte reserve which works so long as
|
||||
// we're only doing one or a few arenas.
|
||||
arena = MD_ArenaAlloc(1ull << 40);
|
||||
|
||||
// parse a string
|
||||
MD_String8 name = MD_S8Lit("<name>");
|
||||
MD_String8 hello_world = MD_S8Lit("hello world");
|
||||
MD_ParseResult parse = MD_ParseWholeString(arena, hello_world_name, hello_world);
|
||||
|
||||
// print the results
|
||||
MD_PrintDebugDumpFromNode(stdout, parse.node, MD_GenerateFlags_All);
|
||||
}
|
||||
Reference in New Issue
Block a user