]>
git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/src/third_party/duktape-1.5.2/examples/guide/primecheck.c
7 static duk_ret_t
native_prime_check(duk_context
*ctx
) {
8 int val
= duk_require_int(ctx
, 0);
9 int lim
= duk_require_int(ctx
, 1);
12 for (i
= 2; i
<= lim
; i
++) {
23 int main(int argc
, const char *argv
[]) {
24 duk_context
*ctx
= NULL
;
26 ctx
= duk_create_heap_default();
28 printf("Failed to create a Duktape heap.\n");
32 duk_push_global_object(ctx
);
33 duk_push_c_function(ctx
, native_prime_check
, 2 /*nargs*/);
34 duk_put_prop_string(ctx
, -2, "primeCheckNative");
36 if (duk_peval_file(ctx
, "prime.js") != 0) {
37 printf("Error: %s\n", duk_safe_to_string(ctx
, -1));
40 duk_pop(ctx
); /* ignore result */
42 duk_get_prop_string(ctx
, -1, "primeTest");
43 if (duk_pcall(ctx
, 0) != 0) {
44 printf("Error: %s\n", duk_safe_to_string(ctx
, -1));
46 duk_pop(ctx
); /* ignore result */
49 duk_destroy_heap(ctx
);