LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
lg_goodies.c File Reference

Functions

char * l_str_new2 (int n,...)
 
char * l_str_cat2 (char *str, int n,...)
 
char * l_str_new3 (const char *format,...)
 
char * l_str_cat3 (char *str, const char *format,...)
 
LG_Path lg_path (const char *s, lg_path_type t)
 
const char * lg_path_resolve (const LG_Path *path)
 
LG_Path lg_path_in_assets_from_fullpath_string (const char *full_path)
 
LG_Path lg_path_in_wrdir_from_fullpath_string (const char *full_path)
 
lg_path_type lg_path_get_type_from_fullpath_string (const char *full_path)
 
zboolean lg_path_string_resolve (char *path)
 
const char * lg_path_type_get_string (lg_path_type type)
 
zboolean lg_path_are_equal (const LG_Path *path1, const LG_Path *path2)
 
void lg_path_info (LG_Path *path)
 
void lg_resolved_path0_free_buffer ()
 
LG_Stack_ilg_stack_i_new (int max_n)
 
void lg_stack_i_free (LG_Stack_i *s)
 
zboolean push_i (LG_Stack_i *s, int v)
 
zboolean pop_i (LG_Stack_i *s, int *v)
 
LG_Stack_flg_stack_f_new (int max_n)
 
void lg_stack_f_free (LG_Stack_f *s)
 
zboolean push_f (LG_Stack_f *s, float v)
 
zboolean pop_f (LG_Stack_f *s, float *v)
 
void lg_stack_show_full_empty_errors (zboolean show_errors)
 

Detailed Description

=== Only really convenient stuff ===

Function Documentation

◆ l_str_new2()

char * l_str_new2 ( int  n,
  ... 
)

Dynamically create a new string made of n sub-strings

Parameters
nNumber of sub-strings
...Sequence of n sub-strings (const char *)
Returns
The new string - should be freed when you're done with it with free2()

◆ l_str_cat2()

char * l_str_cat2 ( char *  str,
int  n,
  ... 
)

Dynamically concanate n sub-strings to a string created with l_str_newN() or l_str_catN()

Parameters
strA dynamically created string
nNumber of sub-strings
...Sequence of n sub-strings (const char *)
Returns
The new string - should be freed when you're done with it with free2()

◆ l_str_new3()

char * l_str_new3 ( const char *  format,
  ... 
)

Dynamically create a new string from a format and (eventual) extra args, similarly to printf() &co

Max string length is arbitrarily set to 16 MiB - should implement that as a setting somewhere

Parameters
formatFormat
...Extra args
Returns
The new string - should be freed when you're done with it with free2()

◆ l_str_cat3()

char * l_str_cat3 ( char *  str,
const char *  format,
  ... 
)

Dynamically concanate a formatted string (from format and extra args) to a string created with l_str_newN() or l_str_catN()

Max string length is arbitrarily set to 16 MiB - should implement that as a setting somewhere

Parameters
strA dynamically created string
formatFormat
...Extra args
Returns
The new string - should be freed when you're done with it with free2()

◆ lg_path()

LG_Path lg_path ( const char *  s,
lg_path_type  t 
)

Create a new LG_Path, ie a path and an associated type, which specify if this path is relative inside the ASSETS folder, or relative inside the APP_WRITABLE folder, or full, or a filename only, or unknown

LG_Path are LOSSLESS, CROSS-APP, AND CROSS-PLATFORM, so you should use them everywhere they are relevant

String max len = LG_PATH_MAX_LEN (see below)

In lg_goodies.h:

#define LG_PATH_MAX_LEN (512 - 1 - 1) // 2nd -1 to keep LG_Path size at 512
typedef int8_t lg_path_type;
enum {IN_ASSETS, IN_APP_WR_DIR, FULL, NAME_ONLY, UNSPECIFIED};
// sizeof(LG_Path) = 512 bytes
typedef struct __attribute__((packed, aligned(4))) {
char s[LG_PATH_MAX_LEN + 1];
lg_path_type t;
Definition lg_goodies.h:20

Usage example:

LG_Path path = lg_path("hello1/hello2", IN_ASSETS)
LG_Path lg_path(const char *s, lg_path_type t)
Definition lg_goodies.c:149
Parameters
sString containing the path - if NULL, path is set to an empty string
tPath type, one of IN_ASSETS, IN_APP_WR_DIR, FULL, NAME_ONLY, UNSPECIFIED - if invalid, set to UNSPECIFIED
Returns
A new LG_Path

◆ lg_path_resolve()

const char * lg_path_resolve ( const LG_Path path)

Resolve LG_PATH, ie get the full path - at runtime

Parameters
pathA LG_Path
Returns
The full path if OK, empty string on error

◆ lg_path_in_assets_from_fullpath_string()

LG_Path lg_path_in_assets_from_fullpath_string ( const char *  full_path)

Return a valid LG_Path with type IN_ASSETS from a valid full path string in ASSETS

Parameters
full_pathString to full path
Returns
LG_Path with type IN_ASSETS

◆ lg_path_in_wrdir_from_fullpath_string()

LG_Path lg_path_in_wrdir_from_fullpath_string ( const char *  full_path)

Return a valid LG_Path with type IN_APP_WR_DIR from a valid full path string in app wr dir

Parameters
full_pathString to full path
Returns
LG_Path with type IN_APP_WR_DIR

◆ lg_path_get_type_from_fullpath_string()

lg_path_type lg_path_get_type_from_fullpath_string ( const char *  full_path)

Return whether a valid full path string points to the ASSETS dir, or the app wr dir, or somewhere else

Parameters
full_pathString to full path
Returns
type A lg_path_type value if it can be determined (ie, IN_ASSETS or IN_APP_WR_DIR), UNSPECIFIED otherwise

◆ lg_path_string_resolve()

zboolean lg_path_string_resolve ( char *  path)

Resolve a path string (not a path) which includes "../", "./" sequences and extra '/' , making it a valid one

-> doesn't return a full path, unless string is a full path

Change path in place

This func is called internally by lg_path_resolve() but you may use it with any 'writable' string

Parameters
pathPath to resolve - will be overwritten
Returns
TRUE if OK, FALSE on error (no changes applied)

◆ lg_path_type_get_string()

const char * lg_path_type_get_string ( lg_path_type  type)

Get string from lg_path_type

IN_ASSETS, IN_APP_WR_DIR, FULL, NAME_ONLY, UNSPECIFIED -> 'IN_ASSETS', 'IN_APP_WR_DIR', 'FULL', 'NAME_ONLY', 'UNSPECIFIED'

Parameters
typelg_path_type value
Returns
String from lg_path_type

◆ lg_path_are_equal()

zboolean lg_path_are_equal ( const LG_Path path1,
const LG_Path path2 
)

Compare two LG_PATH

Parameters
path1A LG_Path
path2Another LG_Path
Returns
TRUE if paths are equal, FALSE otherwise

◆ lg_path_info()

void lg_path_info ( LG_Path path)

Print out LG_Path info, ie string and type

Parameters
pathPointer to a LG_Path

◆ lg_resolved_path0_free_buffer()

void lg_resolved_path0_free_buffer ( )

Free resolved_path0 buffer - called by lg_quit(), you should never call this fuction directly

◆ lg_stack_i_new()

LG_Stack_i * lg_stack_i_new ( int  max_n)

Create and init a new LG_Stack_i instance

Parameters
max_nMax num of elements of the stack
Returns
A new LG_Stack_i instance if OK, NULL on error

◆ lg_stack_i_free()

void lg_stack_i_free ( LG_Stack_i s)

Free a LG_Stack_i instance and all associated resources

Parameters
sA LG_Stack_i instance

◆ push_i()

zboolean push_i ( LG_Stack_i s,
int  v 
)

Push int value into LG_Stack_i

Parameters
sAddr of LG_Stack_i
vint value
Returns
TRUE if OK, FALSE otherwise

◆ pop_i()

zboolean pop_i ( LG_Stack_i s,
int *  v 
)

Pop int value from LG_Stack_i

Parameters
sAddr of LG_Stack_i
vAddr of int
Returns
TRUE if OK, FALSE otherwise

◆ lg_stack_f_new()

LG_Stack_f * lg_stack_f_new ( int  max_n)

Create and init a new LG_Stack_f instance

Parameters
max_nMax num of elements of the stack
Returns
A new LG_Stack_f instance if OK, NULL on error

◆ lg_stack_f_free()

void lg_stack_f_free ( LG_Stack_f s)

Free a LG_Stack_f instance and all associated resources

Parameters
sA LG_Stack_f instance

◆ push_f()

zboolean push_f ( LG_Stack_f s,
float  v 
)

Push float value into LG_Stack_f

Parameters
sAddr of LG_Stack_f
vfloat value
Returns
TRUE if OK, FALSE otherwise

◆ pop_f()

zboolean pop_f ( LG_Stack_f s,
float *  v 
)

Pop float value from LG_Stack_f

Parameters
sAddr of LG_Stack_f
vAddr of float
Returns
TRUE if OK, FALSE otherwise

◆ lg_stack_show_full_empty_errors()

void lg_stack_show_full_empty_errors ( zboolean  show_errors)

Show / don't show (= default) "Stack is full" / "Stack is empty" errors, which can be numerous

Parameters
show_errors