Skip to content

Commit

Permalink
Add module loading support to 'duk' example
Browse files Browse the repository at this point in the history
  • Loading branch information
svaarala committed May 29, 2016
1 parent 1299462 commit aee3da7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/cmdline/duk_cmdline.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* - To enable Duktape.Logger, define DUK_CMDLINE_LOGGING_SUPPORT
* and add extras/logging/duk_logging.c to compilation.
*
* - To enable Duktape 1.x module loading support (require(),
* Duktape.modSearch() etc), define DUK_CMDLINE_MODULE_SUPPORT and add
* extras/module-duktape/duk_module_duktape.c to compilation.
*
* - To enable linenoise and other fancy stuff, compile with -DDUK_CMDLINE_FANCY.
* It is not the default to maximize portability. You can also compile in
* support for example allocators, grep for DUK_CMDLINE_*.
Expand Down Expand Up @@ -60,6 +64,9 @@
#if defined(DUK_CMDLINE_LOGGING_SUPPORT)
#include "duk_logging.h"
#endif
#if defined(DUK_CMDLINE_MODULE_SUPPORT)
#include "duk_module_duktape.h"
#endif
#if defined(DUK_CMDLINE_FILEIO)
#include <errno.h>
#endif
Expand Down Expand Up @@ -1133,6 +1140,11 @@ static duk_context *create_duktape_heap(int alloc_provider, int debugger, int aj
duk_logging_init(ctx, 0 /*flags*/);
#endif

/* Register require() (removed in Duktape 2.x). */
#if defined(DUK_CMDLINE_MODULE_SUPPORT)
duk_module_duktape_init(ctx);
#endif

#if defined(DUK_CMDLINE_FILEIO)
duk_push_c_function(ctx, fileio_read_file, 1 /*nargs*/);
duk_put_global_string(ctx, "readFile");
Expand Down

0 comments on commit aee3da7

Please sign in to comment.