Name
SPVM::Document::NativeAPI::CFunction - C Function Native APIs
Description
Native APIs for C standard functions.
Details
These native APIs are provided to safely invoke C standard functions linked into the SPVM runtime.
These APIs are designed to allow precompiled C source code to function without depending on C standard header include paths, which is essential when performing JIT compilation using TCC or MIR.
Usage
SPVM_API_CFUNC* api_cfunc = env->api->cfunc;
Native APIs
c_strlen
size_t (*c_strlen)(SPVM_ENV* env, SPVM_VALUE* stack, const char* str);
A wrapper for the C standard function strlen.
c_memcpy
void* (*c_memcpy)(SPVM_ENV* env, SPVM_VALUE* stack, void* dest, const void* src, size_t n);
A wrapper for the C standard function memcpy.
c_memset
void* (*c_memset)(SPVM_ENV* env, SPVM_VALUE* stack, void* s, int c, size_t n);
A wrapper for the C standard function memset.
c_memcmp
int (*c_memcmp)(SPVM_ENV* env, SPVM_VALUE* stack, const void* s1, const void* s2, size_t n);
A wrapper for the C standard function memcmp.
c_strtoll
long long (*c_strtoll)(SPVM_ENV* env, SPVM_VALUE* stack, const char* str, char** endptr, int base);
A wrapper for the C standard function strtoll.
c_strtof
float (*c_strtof)(SPVM_ENV* env, SPVM_VALUE* stack, const char* str, char** endptr);
A wrapper for the C standard function strtof.
c_strtod
double (*c_strtod)(SPVM_ENV* env, SPVM_VALUE* stack, const char* str, char** endptr);
A wrapper for the C standard function strtod.
c_fputs
int (*c_fputs)(SPVM_ENV* env, SPVM_VALUE* stack, const char* s, void* stream);
A wrapper for the C standard function fputs.
c_fgetc
int (*c_fgetc)(SPVM_ENV* env, SPVM_VALUE* stack, void* stream);
A wrapper for the C standard function fgetc.
c_snprintf_len
int32_t (*c_snprintf_len)(SPVM_ENV* env, SPVM_VALUE* stack, char* s, size_t n, const char* format, SPVM_VALUE* args, int32_t args_length);
A wrapper for the C standard function snprintf.
This function receives arguments as an array of SPVM_VALUE instead of variadic arguments.
The format specifiers in the format string must match the types of the values stored in args.
For example: * %d, %x: Expects an ival (int32_t). * %ld, %lld (or PRId64): Expects a lval (int64_t). * %f, %g: Expects a dval (double). * %s, %p: Expects an address (void*).
Returns the number of characters that would have been written if n had been sufficiently large, not counting the terminating null character.
Native C Function API IDs
0 c_strlen
1 c_memcpy
2 c_memset
3 c_memcmp
4 c_strtoll
5 c_strtof
6 c_strtod
7 c_fputs
8 c_fgetc
9 c_snprintf_len
See Also
Copyright & License
Copyright (c) 2026 Yuki Kimoto
MIT License