Last active
August 29, 2015 14:13
-
-
Save andriybuday/6db8d6213e03b40ed6b7 to your computer and use it in GitHub Desktop.
Integrating Edge.js into C# project
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
(function () { | |
if ('undefined' === typeof Calc2D) { | |
Calc2D = {}; | |
if ('undefined' !== typeof window) { | |
window.Calc2D = Calc2D; | |
} else { | |
GLOBAL.Calc2D = Calc2D; | |
} | |
} | |
Calc2D.add2DPoints = function (a, b) { | |
return { | |
x: a.x + b.x, | |
y: a.y + b.y | |
}; | |
}; | |
})(); |
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
var Calc2D = require('../../calc2D.js'); | |
module.exports = function (data, callback) { | |
var obj = global[data.className]; | |
var result = obj[data.functionName](data.a, data.b); | |
callback(null, result); | |
}; |
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
using System; | |
using EdgeJs; | |
namespace LearnEdgeJs | |
{ | |
class Program | |
{ | |
public void Start() | |
{ | |
var func = Edge.Func(@"return require('../edgeEntryPoint.js')"); | |
var invoke = func.Invoke(new | |
{ | |
className = "Calc2D", | |
functionName = "add2DPoints", | |
a = new { x = 1, y = 2 }, | |
b = new { x = 10, y = 20 } | |
}); | |
var c = (dynamic)invoke.Result; | |
Console.WriteLine("C: y={0}, y={1}", c.x, c.y); | |
} | |
static void Main(string[] args) | |
{ | |
new Program().Start(); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment