##- # Dedicated to the public domain # # Date: August 2016 # Modified: 2016-10-10/04:45-0400 ##+ # # uniduk.icn, load the Duktape ECMAScript engine # # tectonics: gcc -std=c99 -o uniduk.so -shared -fpic uniduk.c duktape.c # procedure main() # embed some Duktape ECMAScript uniduk := loadfunc("./uniduk.so", "uniduk") unidukfile := loadfunc("./uniduk.so", "unidukFile") unidukdone := loadfunc("./uniduk.so", "unidukDone") # numbers code := "1 + 2;" write("Attempt: ", code) result := uniduk(code) write("Unicon: uniduk completed with ", result) # no result, but side effect code := "print('Duktape print'); var r = 7 * 6;" write("Attempt: ", code) result := uniduk(code) write("Unicon: uniduk completed with ", result) # var r, number, set from previous script code := "r;" write("Attempt: ", code) result := uniduk(code) write("Unicon: uniduk completed with ", result) # string code := "'abc';" write("Attempt: ", code) result := uniduk(code) write("Unicon: uniduk completed with ", result) # JSON (Duktape custom JX format, readable JSON) code := "var obj = {foo: 0/0, bar: [1, undefined, 3]};_ Duktape.enc('jx', obj);" write("Attempt: ", code) result := uniduk(code) write("Unicon: uniduk completed with ", result) # evaluate a test script from file filename := "uniduk.js" write("Attempt: ", filename) result := unidukfile(filename) # close up write("Unicon: Unload Duktape") unidukdone() end