mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.5 KiB
57 lines
1.5 KiB
/*===
|
|
Hello world!
|
|
return value is: 123.000000
|
|
result is: 'TESTSTRING'
|
|
Hello world!
|
|
return value is: 123 (rc=0)
|
|
return value is: Error: eval error (rc=1)
|
|
return value is: SyntaxError: invalid object literal (line 1) (rc=1)
|
|
top=0
|
|
Hello world!
|
|
top=0
|
|
Hello world!
|
|
no result, rc=0
|
|
top=0
|
|
no result, rc=1
|
|
top: 0
|
|
===*/
|
|
|
|
void test(duk_context *ctx) {
|
|
int rc;
|
|
|
|
duk_eval_string(ctx, "print('Hello world!'); 123;");
|
|
printf("return value is: %lf\n", duk_get_number(ctx, -1));
|
|
duk_pop(ctx);
|
|
|
|
duk_eval_string(ctx, "'testString'.toUpperCase()");
|
|
printf("result is: '%s'\n", duk_get_string(ctx, -1));
|
|
duk_pop(ctx);
|
|
|
|
rc = duk_peval_string(ctx, "print('Hello world!'); 123;");
|
|
printf("return value is: %s (rc=%d)\n", duk_safe_to_string(ctx, -1), rc);
|
|
duk_pop(ctx);
|
|
|
|
rc = duk_peval_string(ctx, "throw new Error('eval error');");
|
|
printf("return value is: %s (rc=%d)\n", duk_safe_to_string(ctx, -1), rc);
|
|
duk_pop(ctx);
|
|
|
|
rc = duk_peval_string(ctx, "throw new Error('eval error'); obj = {");
|
|
printf("return value is: %s (rc=%d)\n", duk_safe_to_string(ctx, -1), rc);
|
|
duk_pop(ctx);
|
|
|
|
/* noresult variants */
|
|
|
|
printf("top=%d\n", duk_get_top(ctx));
|
|
duk_eval_string_noresult(ctx, "print('Hello world!'); 123;");
|
|
|
|
printf("top=%d\n", duk_get_top(ctx));
|
|
rc = duk_peval_string_noresult(ctx, "print('Hello world!'); 123;");
|
|
printf("no result, rc=%d\n", rc);
|
|
|
|
printf("top=%d\n", duk_get_top(ctx));
|
|
rc = duk_peval_string_noresult(ctx, "print('Hello world!'); obj = {");
|
|
printf("no result, rc=%d\n", rc);
|
|
|
|
printf("top: %d\n", duk_get_top(ctx));
|
|
}
|
|
|
|
|