This commit is contained in:
Jonathan Campbell
2019-03-26 13:58:10 -07:00
parent a307927f0f
commit 99a183b50f
2 changed files with 42 additions and 0 deletions

View File

@@ -29,6 +29,36 @@ extern "C" {
#define scvprintf vfprintf
#endif
SQInteger hello1(HSQUIRRELVM v) {
printf("hello1 ");
for (SQInteger n=1;n <= sq_gettop(v);n++) {
switch (sq_gettype(v,n)) {
case OT_NULL:
printf("(null) ");
break;
case OT_INTEGER: {
SQInteger i = 0;
sq_getinteger(v,n,&i);
printf("%lld ",(long long)i);
} break;
case OT_FLOAT: {
SQFloat i = 0;
sq_getfloat(v,n,&i);
printf("%.3f ",(double)i);
} break;
case OT_STRING: {
const SQChar *i = NULL;
sq_getstring(v,n,&i);
printf("\"%s\" ",(const char*)i);
} break;
default:
break;
};
}
printf("\n");
return 0;
}
void printfunc(HSQUIRRELVM SQ_UNUSED_ARG(v),const SQChar *s,...)
{
va_list vl;
@@ -83,6 +113,14 @@ int main(int argc,char **argv) {
blob[rd] = 0;
}
{
sq_pushroottable(sq);
sq_pushstring(sq,"hello1",-1);
sq_newclosure(sq,hello1,0);
sq_newslot(sq,-3,SQFalse);
sq_pop(sq,1);
}
if (SQ_SUCCEEDED(sq_compilebuffer(sq,blob,strlen(blob),"file",SQTrue))) {
sq_pushroottable(sq);
if (SQ_SUCCEEDED(sq_call(sq,1,0,SQTrue))) {

View File

@@ -29,4 +29,8 @@ function aaa(x,y) {
}
print(aaa(4,3)+"\n");
hello1();
hello1(1);
hello1(23.44);
hello1("Hello world");