/*
 *
 * Created by jiaqiang.ye@lnxall.com
 *
 * Simple C Module for Rust Application
 *
 * 2022/01/09
 *
 */

#ifndef RUST_CMOD_H
#define RUST_CMOD_H 1
#ifdef __cplusplus
extern "C" {
#endif

unsigned char * cmod_malloc(
    unsigned long msize,
    unsigned long * mptr);

void cmod_memset(unsigned long mptr,
    int value, unsigned long msize);

void cmod_free(unsigned long mptr);

long cmod_strtol(const char * mptr, int * perror, int base);

unsigned long cmod_strtoul(const char * mptr, int * perror, int base);

double cmod_strtod(const char * mptr, int * perror);

char * cmod_gwsn(void);

unsigned long clua_load(const char * script);

void clua_free(unsigned long luast);

int clua_topval(unsigned long luast, int ntop);

char * clua_getupval(unsigned long luast, int idx);

union clua_val {
	signed int               val_s32;
	unsigned int             val_u32;
	double                   val_float;
	char *                   val_str;
};

#define CMODLUA_VAL_NONE     0
#define CMODLUA_VAL_S32      1
#define CMODLUA_VAL_U32      2
#define CMODLUA_VAL_FLOAT    3
#define CMODLUA_VAL_STR      4

struct clua_value {
	unsigned int             val_type;
	union clua_val           val_cmod;
};

int clua_tpush(unsigned long luast, int maxnum,
	const char * keyn, const struct clua_value * pval);

int clua_tcall(unsigned long luast, const char * funcn, struct clua_value * pval);

int clua_getval(unsigned long luast, int idx, struct clua_value * pval);

int clua_setval(unsigned long luast, int idx, const struct clua_value * pval);

int clua_call(unsigned long luast, const char * funcn,
	struct clua_value * pval, const struct clua_value * parg);

#ifdef __cplusplus
}
#endif
#endif
