Last active
February 8, 2021 18:28
-
-
Save morisil/110463b6f632e17604b7b39bbc165720 to your computer and use it in GitHub Desktop.
An example of how kotlinjs compiler is tranforming openrndr math into JavaScript
This file contains hidden or 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
(function (root, factory) { | |
if (typeof define === 'function' && define.amd) | |
define(['exports'], factory); | |
else if (typeof exports === 'object') | |
factory(module.exports); | |
else | |
root['openrndr-kotlinjs-test'] = factory(typeof this['openrndr-kotlinjs-test'] === 'undefined' ? {} : this['openrndr-kotlinjs-test']); | |
}(this, function (_) { | |
'use strict'; | |
NodeJsOutput_0.prototype = Object.create(BaseOutput.prototype); | |
NodeJsOutput_0.prototype.constructor = NodeJsOutput_0; | |
BufferedOutput_0.prototype = Object.create(BaseOutput.prototype); | |
BufferedOutput_0.prototype.constructor = BufferedOutput_0; | |
BufferedOutputToConsoleLog_0.prototype = Object.create(BufferedOutput_0.prototype); | |
BufferedOutputToConsoleLog_0.prototype.constructor = BufferedOutputToConsoleLog_0; | |
function Annotation() { | |
} | |
Annotation.$metadata$ = { | |
simpleName: 'Annotation', | |
kind: 'interface', | |
interfaces: [] | |
}; | |
var output; | |
function BaseOutput() { | |
} | |
BaseOutput.prototype.println_5 = function () { | |
this.print_2('\n'); | |
}; | |
BaseOutput.prototype.println_6 = function (message) { | |
this.print_2(message); | |
this.println_5(); | |
}; | |
BaseOutput.$metadata$ = { | |
simpleName: 'BaseOutput', | |
kind: 'class', | |
interfaces: [] | |
}; | |
function NodeJsOutput_0(outputStream) { | |
BaseOutput.call(this); | |
this._outputStream = outputStream; | |
} | |
NodeJsOutput_0.prototype.print_2 = function (message) { | |
var messageString = String(message); | |
this._outputStream.write(messageString); | |
}; | |
NodeJsOutput_0.$metadata$ = { | |
simpleName: 'NodeJsOutput', | |
kind: 'class', | |
interfaces: [] | |
}; | |
function BufferedOutputToConsoleLog_0() { | |
BufferedOutput_0.call(this); | |
} | |
BufferedOutputToConsoleLog_0.prototype.print_2 = function (message) { | |
var s = String(message); | |
var tmp0_nativeLastIndexOf_0 = s; | |
var tmp1_nativeLastIndexOf_0 = '\n'; | |
var tmp2_nativeLastIndexOf_0 = 0; | |
var i = tmp0_nativeLastIndexOf_0.lastIndexOf(tmp1_nativeLastIndexOf_0, tmp2_nativeLastIndexOf_0); | |
if (i >= 0) { | |
var tmp0_this = this; | |
var tmp = tmp0_this._get_buffer__0(); | |
var tmp3_substring_0 = s; | |
var tmp4_substring_0 = 0; | |
tmp0_this._set_buffer__0(tmp + tmp3_substring_0.substring(tmp4_substring_0, i)); | |
this.flush(); | |
var tmp5_substring_0 = s; | |
var tmp6_substring_0 = i + 1 | 0; | |
s = tmp5_substring_0.substring(tmp6_substring_0); | |
}var tmp1_this = this; | |
tmp1_this._set_buffer__0(tmp1_this._get_buffer__0() + s); | |
}; | |
BufferedOutputToConsoleLog_0.prototype.flush = function () { | |
(function () { | |
var $externalVarargReceiverTmp = console; | |
return $externalVarargReceiverTmp.log.apply($externalVarargReceiverTmp, [].concat([this._get_buffer__0()])); | |
}.call(this)); | |
this._set_buffer__0(''); | |
}; | |
BufferedOutputToConsoleLog_0.$metadata$ = { | |
simpleName: 'BufferedOutputToConsoleLog', | |
kind: 'class', | |
interfaces: [] | |
}; | |
function BufferedOutput_0() { | |
BaseOutput.call(this); | |
this._buffer = ''; | |
} | |
BufferedOutput_0.prototype._set_buffer__0 = function (_set___) { | |
this._buffer = _set___; | |
}; | |
BufferedOutput_0.prototype._get_buffer__0 = function () { | |
return this._buffer; | |
}; | |
BufferedOutput_0.prototype.print_2 = function (message) { | |
var tmp0_this = this; | |
var tmp = tmp0_this; | |
var tmp_0 = tmp0_this._buffer; | |
tmp._buffer = tmp_0 + String(message); | |
}; | |
BufferedOutput_0.$metadata$ = { | |
simpleName: 'BufferedOutput', | |
kind: 'class', | |
interfaces: [] | |
}; | |
function println(message) { | |
output.println_6(message); | |
} | |
function output$init$() { | |
var isNode_2 = typeof process !== 'undefined' && process.versions && !!process.versions.node; | |
return isNode_2 ? new NodeJsOutput_0(process.stdout) : new BufferedOutputToConsoleLog_0(); | |
} | |
function SerializableWith() { | |
} | |
SerializableWith.$metadata$ = { | |
simpleName: 'SerializableWith', | |
kind: 'class', | |
interfaces: [Annotation], | |
associatedObjectKey: 0 | |
}; | |
function main() { | |
println((new Vector2(2.0, 2.0)).plus(new Vector2(2.0, 2.0))); | |
} | |
function LinearType() { | |
} | |
LinearType.$metadata$ = { | |
simpleName: 'LinearType', | |
kind: 'interface', | |
interfaces: [] | |
}; | |
function Companion_0() { | |
Companion_instance = this; | |
this._ZERO = new Vector2(0.0, 0.0); | |
this._ONE = new Vector2(1.0, 1.0); | |
this._UNIT_X = new Vector2(1.0, 0.0); | |
this._UNIT_Y = new Vector2(0.0, 1.0); | |
this._INFINITY = new Vector2(Infinity, Infinity); | |
} | |
Companion_0.$metadata$ = { | |
simpleName: 'Companion', | |
kind: 'object', | |
interfaces: [] | |
}; | |
var Companion_instance; | |
function Companion_getInstance() { | |
if (Companion_instance == null) | |
new Companion_0(); | |
return Companion_instance; | |
} | |
function Vector2(x, y) { | |
Companion_getInstance(); | |
this._x = x; | |
this._y = y; | |
} | |
Vector2.prototype.plus = function (vector2) { | |
return new Vector2(this._x + vector2._x, this._y + vector2._y); | |
}; | |
Vector2.prototype.toString = function () { | |
return '' + 'Vector2(x=' + this._x + ', y=' + this._y + ')'; | |
}; | |
Vector2.$metadata$ = { | |
simpleName: 'Vector2', | |
kind: 'class', | |
interfaces: [LinearType] | |
}; | |
output = output$init$(); | |
var $com = _.com || (_.com = {}); | |
var $com$xemantic = $com.xemantic || ($com.xemantic = {}); | |
var $com$xemantic$test = $com$xemantic.test || ($com$xemantic.test = {}); | |
var $com$xemantic$test$openrndr = $com$xemantic$test.openrndr || ($com$xemantic$test.openrndr = {}); | |
var $com$xemantic$test$openrndr$kotlinjs = $com$xemantic$test$openrndr.kotlinjs || ($com$xemantic$test$openrndr.kotlinjs = {}); | |
$com$xemantic$test$openrndr$kotlinjs.main = main; | |
main(); | |
return _; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment