Browse Source

update api docs for eval/compile with filename info

pull/1/head
Sami Vaarala 11 years ago
parent
commit
9901ebf1e2
  1. 13
      website/api/duk_compile.txt
  2. 3
      website/api/duk_compile_file.txt
  3. 6
      website/api/duk_compile_string.txt
  4. 7
      website/api/duk_eval.txt
  5. 3
      website/api/duk_eval_file.txt
  6. 4
      website/api/duk_eval_string.txt

13
website/api/duk_compile.txt

@ -2,12 +2,14 @@
void duk_compile(duk_context *ctx, int flags);
=stack
[ ... source! ] -> [ ... function! ]
[ ... source! filename! ] -> [ ... function! ]
=summary
<p>Compile Ecmascript source code and replace it with a compiled function
object (the code is not executed). May throw a <tt>SyntaxError</tt> for any
compile-time errors (in addition to the usual internal errors like out-of-memory,
object (the code is not executed). The <tt>filename</tt> argument is stored
as the <tt>fileName</tt> property of the resulting function, and is the name
used in e.g. tracebacks to identify the function. May throw a <tt>SyntaxError</tt>
for any compile-time errors (in addition to the usual internal errors like out-of-memory,
internal limit errors, etc).</p>
<p>The following flags may be given:</p>
@ -109,14 +111,16 @@ DUK_COMPILE_FUNCTION is currently unimplemented.
duk_push_string(ctx, "print('program');\n"
"function hello() { print('Hello world!'); }\n"
"123;");
duk_push_string(ctx, "hello");
duk_compile(ctx, 0);
duk_call(ctx, 0); /* [ func ] -> [ result ] */
duk_call(ctx, 0); /* [ func filename ] -> [ result ] */
printf("program result: %lf\n", duk_get_number(ctx, -1));
duk_pop(ctx);
/* Eval code */
duk_push_string(ctx, "2+3");
duk_push_string(ctx, "eval");
duk_compile(ctx, DUK_COMPILE_EVAL);
duk_call(ctx, 0); /* [ func ] -> [ result ] */
printf("eval result: %lf\n", duk_get_number(ctx, -1));
@ -125,6 +129,7 @@ duk_pop(ctx);
/* Function code */
duk_push_string(ctx, "function (x,y) { return x+y; }");
duk_push_string(ctx, "function");
duk_compile(ctx, DUK_COMPILE_FUNCTION);
duk_push_int(ctx, 5);
duk_push_int(ctx, 6);

3
website/api/duk_compile_file.txt

@ -7,7 +7,8 @@ void duk_compile_file(duk_context *ctx, int flags, const char *path);
=summary
<p>Like
<tt><a href="#duk_compile">duk_compile()</a></tt>, but the compile input
is given as a filename.</p>
is given as a filename. The filename associated with the result function
is <tt>path</tt> as is.</p>
=example
duk_compile_file(ctx, 0, "test.js");

6
website/api/duk_compile_string.txt

@ -1,5 +1,5 @@
=proto
void duk_compile_string(duk_context *ctx, int flags, const char *str);
void duk_compile_string(duk_context *ctx, int flags, const char *src);
=stack
[ ... ] -> [ ... function! ]
@ -7,7 +7,9 @@ void duk_compile_string(duk_context *ctx, int flags, const char *str);
=summary
<p>Like
<tt><a href="#duk_compile">duk_compile()</a></tt>, but the compile input
is given as a C string.</p>
is given as a C string. The filename associated with the function is
automatically provided from the <tt>__FILE__</tt> preprocessor define
of the caller.</p>
=example
duk_compile_string(ctx, 0, "print('program code');");

7
website/api/duk_eval.txt

@ -7,14 +7,17 @@ void duk_eval(duk_context *ctx);
=summary
<p>Evaluate the Ecmascript source code at the top of the stack, and leave a single
return value on top of the stack. May throw an error, errors are not caught
automatically.</p>
automatically. The filename associated with the temporary eval function is
automatically provided from the <tt>__FILE__</tt> preprocessor define
of the caller.</p>
<p>This is simply a shortcut for:</p>
<p>This is essentially a shortcut for:</p>
<pre class="c-code">
int flags = DUK_COMPILE_EVAL;
if (duk_is_strict_call(ctx)) {
flags |= DUK_COMPILE_STRICT;
}
duk_push_string(ctx, __FILE__);
duk_compile(ctx, flags);
duk_call(ctx, 0);
</pre>

3
website/api/duk_eval_file.txt

@ -7,7 +7,8 @@ void duk_eval_file(duk_context *ctx, const char *path);
=summary
<p>Like
<tt><a href="#duk_eval">duk_eval()</a></tt>, but the eval input
is given as a filename.</p>
is given as a filename. The filename associated with the temporary
function created for the eval code is <tt>path</tt> as is.</p>
=example
duk_eval_string(ctx, "test.js");

4
website/api/duk_eval_string.txt

@ -7,7 +7,9 @@ void duk_eval_string(duk_context *ctx, const char *str);
=summary
<p>Like
<tt><a href="#duk_eval">duk_eval()</a></tt>, but the eval input
is given as a C string.</p>
is given as a C string. The filename associated with the temporary
is automatically provided from the <tt>__FILE__</tt> preprocessor define
of the caller.</p>
=example
duk_eval_string(ctx, "'testString'.toUpperCase()");

Loading…
Cancel
Save