Dummy module should also show how to define constants
This commit is contained in:
parent
b7caeefded
commit
9313276e09
|
@ -1,5 +1,10 @@
|
||||||
#include "dummy.h"
|
#include "dummy.h"
|
||||||
|
|
||||||
|
static void PSHARP_DUMMY_CONSTANT_Const(ph7_value *pVal, void *pUserData) {
|
||||||
|
SXUNUSED(pUserData); /* cc warning */
|
||||||
|
ph7_value_bool(pVal, 1);
|
||||||
|
}
|
||||||
|
|
||||||
int psharp_dummy_function(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
int psharp_dummy_function(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||||
SyString dummy;
|
SyString dummy;
|
||||||
const char *text = "Hello world from dummy module!";
|
const char *text = "Hello world from dummy module!";
|
||||||
|
@ -14,6 +19,12 @@ PH7_PRIVATE sxi32 initializeModule(ph7_vm *pVm, ph7_real *ver, SyString *desc) {
|
||||||
|
|
||||||
desc->zString = MODULE_DESC;
|
desc->zString = MODULE_DESC;
|
||||||
*ver = MODULE_VER;
|
*ver = MODULE_VER;
|
||||||
|
for(n = 0; n < SX_ARRAYSIZE(dummyConstList); ++n) {
|
||||||
|
rc = ph7_create_constant(&(*pVm), dummyConstList[n].zName, dummyConstList[n].xExpand, &(*pVm));
|
||||||
|
if(rc != SXRET_OK) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
for(n = 0 ; n < SX_ARRAYSIZE(dummyFuncList) ; ++n) {
|
for(n = 0 ; n < SX_ARRAYSIZE(dummyFuncList) ; ++n) {
|
||||||
rc = ph7_create_function(&(*pVm), dummyFuncList[n].zName, dummyFuncList[n].xFunc, &(*pVm));
|
rc = ph7_create_function(&(*pVm), dummyFuncList[n].zName, dummyFuncList[n].xFunc, &(*pVm));
|
||||||
if(rc != SXRET_OK) {
|
if(rc != SXRET_OK) {
|
||||||
|
|
|
@ -10,9 +10,16 @@
|
||||||
/* Forward reference & declaration */
|
/* Forward reference & declaration */
|
||||||
PH7_PRIVATE sxi32 initializeModule(ph7_vm *pVm, ph7_real *ver, SyString *desc);
|
PH7_PRIVATE sxi32 initializeModule(ph7_vm *pVm, ph7_real *ver, SyString *desc);
|
||||||
|
|
||||||
|
/* Constants provided by DUMMY module */
|
||||||
|
static void PSHARP_DUMMY_CONSTANT_Const(ph7_value *pVal, void *pUserData);
|
||||||
|
|
||||||
/* Functions provided by DUMMY module */
|
/* Functions provided by DUMMY module */
|
||||||
int psharp_dummy_function(ph7_context *pCtx, int nArg, ph7_value **apArg);
|
int psharp_dummy_function(ph7_context *pCtx, int nArg, ph7_value **apArg);
|
||||||
|
|
||||||
|
static const ph7_builtin_constant dummyConstList[] = {
|
||||||
|
{"DUMMY_CONSTANT", PSHARP_DUMMY_CONSTANT_Const},
|
||||||
|
};
|
||||||
|
|
||||||
static const ph7_builtin_func dummyFuncList[] = {
|
static const ph7_builtin_func dummyFuncList[] = {
|
||||||
{"dummy_function", psharp_dummy_function },
|
{"dummy_function", psharp_dummy_function },
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue