Last active
August 13, 2021 17:52
-
-
Save uyjulian/b9d41c776112eb4a919bcb6893ed0174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Outputting various data types to the console | |
Debug.message("Hello world!"); | |
KirikiriEmscriptenInterface.evalJS("window.alert('Hello world from JS!')"); | |
KirikiriEmscriptenInterface.evalJS("Module.evalTJS('Debug.message(\"Hello world from TJS!\")')"); | |
Debug.message(KirikiriEmscriptenInterface.evalJS("'JS string'")); | |
Debug.message(KirikiriEmscriptenInterface.evalJS("Module.evalTJS('\"TJS string\"')")); | |
Debug.message(KirikiriEmscriptenInterface.evalJS("123")); | |
Debug.message(KirikiriEmscriptenInterface.evalJS("Module.evalTJS('123')")); | |
Debug.message(KirikiriEmscriptenInterface.evalJS("3.14")); | |
Debug.message(KirikiriEmscriptenInterface.evalJS("Module.evalTJS('3.14')")); | |
Debug.message(KirikiriEmscriptenInterface.evalJS("true")); | |
Debug.message(KirikiriEmscriptenInterface.evalJS("Module.evalTJS('true')")); | |
// Using the console | |
global.console = KirikiriEmscriptenInterface.evalJS("console"); | |
global.console.log("Hello"); | |
// Using window.alert | |
global.window = KirikiriEmscriptenInterface.evalJS("window"); | |
global.window.alert("Hello world from JS->TJS wrapper!"); | |
// Wrapping console.log through through TJS and JS multiple times | |
Debug.message(KirikiriEmscriptenInterface.evalJS("Module.evalTJS('global.console.log')('Hello world from TJS->JS wrapper!')")); | |
// Using fetch object | |
global.window.fetch('./').then(function(a){global.console.log(a);}); | |
// Exception handling | |
(function(){try{KirikiriEmscriptenInterface.evalJS("throw 'Example exception'");}catch(e){Debug.message(e); throw e;}})(); | |
(function(){try{throw "Example TJS exception";}catch(e){Debug.message(e); throw e;}})(); | |
(function(){try{throw new Exception("Example TJS exception object");}catch(e){Debug.message(e); throw e;}})(); | |
(function(){try{KirikiriEmscriptenInterface.evalJS("throw new Error('Example JS error object')");}catch(e){Debug.message(e); throw e;}})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment