mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
parent
1c9065510f
commit
f3baa05195
2 changed files with 14 additions and 4 deletions
|
@ -1,2 +1,2 @@
|
|||
NativePrint('Hello world!\n');
|
||||
NativePrint('2+3=' + NativeAdd(2, 3) + '\n');
|
||||
console.log('Hello world!\n');
|
||||
console.log('2+3=' + NativeAdd(2, 3) + '\n');
|
||||
|
|
|
@ -42,11 +42,21 @@ int main(int argc, char *argv[]) {
|
|||
duk_context *ctx;
|
||||
showcrashreports();
|
||||
ctx = duk_create_heap_default();
|
||||
duk_push_c_function(ctx, NativePrint, DUK_VARARGS);
|
||||
duk_put_global_string(ctx, "NativePrint");
|
||||
|
||||
/* define NativeAdd() */
|
||||
duk_push_c_function(ctx, NativeAdd, DUK_VARARGS);
|
||||
duk_put_global_string(ctx, "NativeAdd");
|
||||
|
||||
/* define console.log() */
|
||||
duk_push_global_object(ctx);
|
||||
duk_push_c_function(ctx, NativePrint, DUK_VARARGS);
|
||||
duk_push_string(ctx, "name");
|
||||
duk_push_string(ctx, "log");
|
||||
duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE);
|
||||
duk_set_magic(ctx, -1, 0);
|
||||
duk_put_prop_string(ctx, -2, "log");
|
||||
duk_put_global_string(ctx, "console");
|
||||
|
||||
CHECK_NE(-1, (fd = open("zip:examples/hello.js", O_RDONLY)));
|
||||
CHECK_NE(-1, fstat(fd, &st));
|
||||
CHECK_NOTNULL((code = gc(calloc(1, st.st_size + 1))));
|
||||
|
|
Loading…
Reference in a new issue