forked from enlightenment/efl
embryo support for varargs... i was just missing native funcs to export
enough info SVN revision: 10656
This commit is contained in:
parent
5b506efe2c
commit
41b8b1cf4d
|
@ -97,11 +97,43 @@ main()
|
||||||
ret = testfn(12345, "A Test String", 7);
|
ret = testfn(12345, "A Test String", 7);
|
||||||
printf("Done. Return value of testfn() was %i\n", ret);
|
printf("Done. Return value of testfn() was %i\n", ret);
|
||||||
|
|
||||||
|
printf("Test varargs...\n");
|
||||||
|
vargs(1, 2, "hello", "there", 8, 9);
|
||||||
|
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
|
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vargs(a, b, ...)
|
||||||
|
{
|
||||||
|
printf("ARGS...\n");
|
||||||
|
printf(" a = %i\n", a);
|
||||||
|
printf(" b = %i\n", b);
|
||||||
|
for (new i = 2; i < numargs(); i++)
|
||||||
|
{
|
||||||
|
new val;
|
||||||
|
new str[100];
|
||||||
|
|
||||||
|
printf(" GET ARG... %i\n", i);
|
||||||
|
if (i < 4)
|
||||||
|
{
|
||||||
|
for (new j = 0; j < (sizeof(str) - 1); j++)
|
||||||
|
{
|
||||||
|
str[j] = getarg(i, j);
|
||||||
|
if (str[j] == 0) break;
|
||||||
|
}
|
||||||
|
printf(" ARG: %s [max %i]\n", str, sizeof(str));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
val = getarg(i);
|
||||||
|
printf(" ARG: %i\n", val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("ARGS DONE.\n");
|
||||||
|
}
|
||||||
|
|
||||||
recurse(val)
|
recurse(val)
|
||||||
{
|
{
|
||||||
printf("Recurse: val = %i\n", val);
|
printf("Recurse: val = %i\n", val);
|
||||||
|
|
|
@ -32,6 +32,13 @@ enum Float_Angle_Mode
|
||||||
RADIAN, DEGREES, GRADES
|
RADIAN, DEGREES, GRADES
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* varags - get numebr of args to a function */
|
||||||
|
native numargs();
|
||||||
|
/* varags - get arg no "arg" */
|
||||||
|
native getarg(arg, index=0);
|
||||||
|
/* varags - set arg no "arg" */
|
||||||
|
native setarg(arg, index=0, value);
|
||||||
|
|
||||||
/* Convert a string into a floating point value */
|
/* Convert a string into a floating point value */
|
||||||
native Float:atof(const string[]);
|
native Float:atof(const string[]);
|
||||||
/* Return the fractional part of a float */
|
/* Return the fractional part of a float */
|
||||||
|
|
|
@ -17,6 +17,7 @@ lib_LTLIBRARIES = libembryo.la
|
||||||
include_HEADERS = Embryo.h
|
include_HEADERS = Embryo.h
|
||||||
libembryo_la_SOURCES = \
|
libembryo_la_SOURCES = \
|
||||||
embryo_amx.c \
|
embryo_amx.c \
|
||||||
|
embryo_args.c \
|
||||||
embryo_float.c \
|
embryo_float.c \
|
||||||
embryo_main.c \
|
embryo_main.c \
|
||||||
embryo_rand.c \
|
embryo_rand.c \
|
||||||
|
|
|
@ -196,6 +196,7 @@ _embryo_program_init(Embryo_Program *ep, void *code)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* init native api for handling floating point - default in embryo */
|
/* init native api for handling floating point - default in embryo */
|
||||||
|
_embryo_args_init(ep);
|
||||||
_embryo_fp_init(ep);
|
_embryo_fp_init(ep);
|
||||||
_embryo_rand_init(ep);
|
_embryo_rand_init(ep);
|
||||||
_embryo_str_init(ep);
|
_embryo_str_init(ep);
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
#include "embryo_private.h"
|
||||||
|
|
||||||
|
/* exported args api */
|
||||||
|
|
||||||
|
static Embryo_Cell
|
||||||
|
_embryo_args_numargs(Embryo_Program *ep, Embryo_Cell *params)
|
||||||
|
{
|
||||||
|
Embryo_Header *hdr;
|
||||||
|
unsigned char *data;
|
||||||
|
Embryo_Cell bytes;
|
||||||
|
|
||||||
|
hdr = (Embryo_Header *)ep->base;
|
||||||
|
data = ep->base + (int)hdr->dat;
|
||||||
|
bytes = *(Embryo_Cell *)(data + (int)ep->frm +
|
||||||
|
(2 * sizeof(Embryo_Cell)));
|
||||||
|
return bytes / sizeof(Embryo_Cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Embryo_Cell
|
||||||
|
_embryo_args_getarg(Embryo_Program *ep, Embryo_Cell *params)
|
||||||
|
{
|
||||||
|
Embryo_Header *hdr;
|
||||||
|
unsigned char *data;
|
||||||
|
Embryo_Cell val;
|
||||||
|
|
||||||
|
if (params[0] != (2 * sizeof(Embryo_Cell))) return 0;
|
||||||
|
hdr = (Embryo_Header *)ep->base;
|
||||||
|
data = ep->base + (int)hdr->dat;
|
||||||
|
val = *(Embryo_Cell *)(data + (int)ep->frm +
|
||||||
|
(((int)params[1] + 3) * sizeof(Embryo_Cell)));
|
||||||
|
val += params[2] * sizeof(Embryo_Cell);
|
||||||
|
val = *(Embryo_Cell *)(data + (int)val);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Embryo_Cell
|
||||||
|
_embryo_args_setarg(Embryo_Program *ep, Embryo_Cell *params)
|
||||||
|
{
|
||||||
|
Embryo_Header *hdr;
|
||||||
|
unsigned char *data;
|
||||||
|
Embryo_Cell val;
|
||||||
|
|
||||||
|
if (params[0] != (3 * sizeof(Embryo_Cell))) return 0;
|
||||||
|
hdr = (Embryo_Header *)ep->base;
|
||||||
|
data = ep->base + (int)hdr->dat;
|
||||||
|
val = *(Embryo_Cell *)(data + (int)ep->frm +
|
||||||
|
(((int)params[1] + 3) * sizeof(Embryo_Cell)));
|
||||||
|
val += params[2] * sizeof(Embryo_Cell);
|
||||||
|
if ((val < 0) || (val >= ep->hea) && (val < ep->stk)) return 0;
|
||||||
|
*(Embryo_Cell *)(data + (int)val) = params[3];
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* functions used by the rest of embryo */
|
||||||
|
|
||||||
|
void
|
||||||
|
_embryo_args_init(Embryo_Program *ep)
|
||||||
|
{
|
||||||
|
embryo_program_native_call_add(ep, "numargs", _embryo_args_numargs);
|
||||||
|
embryo_program_native_call_add(ep, "getarg", _embryo_args_getarg);
|
||||||
|
embryo_program_native_call_add(ep, "setarg", _embryo_args_setarg);
|
||||||
|
}
|
|
@ -279,6 +279,7 @@ struct _Embryo_Header
|
||||||
int nametable; /* name table, file version 7 only */
|
int nametable; /* name table, file version 7 only */
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
void _embryo_args_init(Embryo_Program *ep);
|
||||||
void _embryo_fp_init(Embryo_Program *ep);
|
void _embryo_fp_init(Embryo_Program *ep);
|
||||||
void _embryo_rand_init(Embryo_Program *ep);
|
void _embryo_rand_init(Embryo_Program *ep);
|
||||||
void _embryo_str_init(Embryo_Program *ep);
|
void _embryo_str_init(Embryo_Program *ep);
|
||||||
|
|
Loading…
Reference in New Issue