4. Global Data
4.1. typedef
All things related to Monolith are contained in a struct
called monolith_d
.
<<typedefs>>=
typedef struct monolith_d monolith_d;
<<global_struct>>=
struct monolith_d {
<<struct_contents>>
};
4.2. global variable
A single instance of monolith_d
is created as a global
variable. The global variable is denoted with the prefix "g_".
<<global_struct>>=
static monolith_d g_monolith;
4.3. getting global variable
This global data can be acquired indirectly with the
function monolith_data_get
.
<<function_declarations>>=
monolith_d* monolith_data_get(void);
<<functions>>=
monolith_d* monolith_data_get(void)
{
return &g_monolith;
}
This can be retrieved in Janet with monolith/data
.
<<core_janet_entries>>=
{
"monolith/data",
j_data,
"Return global pointer to Monolith.\n"
},
<<janet_functions>>=
static Janet j_data(int32_t argc, Janet *argv)
{
janet_fixarity(argc, 0);
return janet_wrap_pointer(monolith_data_get());
}
4.4. data init
The monolith data is initialized with the function
monolith_init
.
<<function_declarations>>=
void monolith_init(monolith_d *m);
<<functions>>=
void monolith_init(monolith_d *m)
{
<<init>>
}
4.5. data cleanup
All allocated data is cleaned with the program
monolith_cleanup
.
<<function_declarations>>=
void monolith_cleanup(monolith_d *m);
<<functions>>=
void monolith_cleanup(monolith_d *m)
{
<<cleanup>>
}
prev | home | next