Sunday, September 9, 2018

DJGPP: Duktape

Duktape is and embeddable JS lib for C/C++. I tried cross compiling it for DJGPP and it works, making it possible for you to run JS in DOS.

Get the source at https://github.com/svaarala/duktape, extract the source, and compile as follows:

i586-pc-msdosdjgpp-gcc -c \
-o duktape.o \
-Isrc/ src/duktape.c \
-DDUK_USE_DATE_FMT_STRFTIME \
-DDUK_USE_DATE_PRS_STRPTIME

Then archive as follows
 
i586-pc-msdosdjgpp-ar ar rvs \
libduk.a \
duktape.o

By default you will find that the library does not come with console.log(), so to get this to work you can compile the static library as follows:
 
i586-pc-msdosdjgpp-gcc -c \
-o duk_cmdline.o \
-Isrc/ ./src/duk_cmdline.c \
-DDUK_CMDLINE_CONSOLE_SUPPORT \
-DDUK_USE_DATE_PRS_STRFTIME \
-DDUK_USE_DATE_FMT_STRFTIME \
-I./include 
 
i586-pc-msdosdjgpp-gcc -c \
-o duk_console.o \
-Isrc/ ./src/duk_console.c \
-DDUK_CMDLINE_CONSOLE_SUPPORT \
-DDUK_USE_DATE_PRS_STRFTIME \
-DDUK_USE_DATE_FMT_STRFTIME \
-I./include

And archive as follows
 
i586-pc-msdosdjgpp-ar ar rvs \
libduktape.a \
duktape.o \
duk_cmdline \
duk_console.o

You can then copy the archive to your DJGPP cross compiler directory . Take note that if you want to use g++, you need to compile with i586-pc-msdosdjgpp-g++ In order to test out the library, you can compile the Duk REPL located in examples/cmdline as follows
 
i586-pc-msdosdjgpp-gcc -W -Wno-unused-function \
-I./include \
-I/home/skullquake/hosts/dos/usr/include \
-L./lib \
-L/home/skullquake/hosts/dos/usr/lib \
-DDUK_CMDLINE_CONSOLE_SUPPORT \
-DDUK_USE_DATE_FMT_STRFTIME \
./examples/cmdline/duk_cmdline.c \
-lduktape \
-lm \
-o ./duk

You can test it out in DOSBOX via the REPL or by passing in [multiple] script files.





I've tested with libraries (e.g. Sylvester, BioNode), and it works...most of the time




Duktape focuses on portability and footprint. Not all JS libs you try out will work, but many will.

You can register C functions and variables with Duktape, allowing executing native functions from JS function calls. I'm currently working on creating bindings for Allegro which allows you to easily code graphics stuff in Allegro without having to recompile the whole program, just reading everything from a JS file.


Sunday, April 29, 2018

Mendix Widgets AMD Modules


In this example define() is used to define an AMD module and is consumed by the widget require()

Wednesday, April 25, 2018

Tuesday, April 24, 2018

Minimal Mendix Widget

Herewith probably the most basic Mendix widget you can write
define(
 [
  "dojo/_base/declare",
  "mxui/widget/_WidgetBase",
 ],
 function(
  declare,
  _WidgetBase,
 ){
  "use strict";
  return declare(
   "mxempty.widget.main",
   [
    _WidgetBase,
   ],
   {
    constructor: function () {
    },
    postCreate: function () {
    }
   }
  );
 }
);
require(["mxempty/widget/main"]);

Does absolutely nothing, but showcases the various parts of a Dojo Dijit widget as used in Mendix. In later posts well take a look at how to extend this.

Mendix Yeoman Generator