GithubHelp home page GithubHelp logo

johnmasen / espresso Goto Github PK

View Code? Open in Web Editor NEW

This project forked from killf/v8net

0.0 3.0 0.0 32.78 MB

☕ V8 to .Net Bridge, Bridge your C# soul to the power of V8 Javascript engine (V8 / NodeJs 8.1.0)

C# 24.40% C++ 65.26% JavaScript 10.33%

espresso's Introduction

Espresso / Espresso-VE / Espresso-ND

V8 js engine with C# (in-process), => Espresso-VE

NodeJS engine with C# (in-process), => Espresso-ND


Espresso (from vroomjs ) is a bridge between the .NET CLR (think C# or F#) and the V8 Javascript engine that uses P/Invoke and a thin C layer (libespr).

Now, Espresso can run on .net20+ and .netcore/.netstandard

so We can run the engine on Windows7+, macOS, and Linux(tested with Ubuntu 16)


Windows7

11

12

13


macOS, x64

26

27


Linux, Ubuntu 16, x64

20

21

23


With Espresso it is possible to execute arbitrary javascript code and get the result as a managed primitive type (for integers, numbers, strings, dates and arrays of primitive types) or as a JsObject wrapper that allows to dynamically access properties and call functions on Javascript objects.

Each JsEngine is an isolated V8 context and all objects allocated on the Javascript side are persistent over multiple calls. It is possible to set and get global variables. Variable values can be primitive types, CLR objects or JsObjects wrapping Javascript objects. CLR instances are kept alive as long as used in Javascript code (so it isn't required to track them in client code: they won't be garbage collected as long as references on the V8 side) and it is possible to access their properties and call methods from JS code.

Current V8 Engine => We use V8 from node v7.10.0

Examples

Execute some Javascript:

	using (var js = new JsEngine()) {
		var x = (int)js.Execute("3.14159+2.71828");
		Console.WriteLine(x);  // prints 5.85987
	}

Create and return a Javascript object, then call a method on it:

	using (var js = new JsEngine()) {
		// Create a global variable on the JS side.
		js.Execute("var x = {'answer':42, 'tellme':function (x) { return x+' '+this.answer; }}");
		// Get it and use "dynamic" to tell the compiler to use runtime binding.
		dynamic x = js.GetVariable("x");
		// Call the method and print the result. This will print:
		// "What is the answer to ...? 42"
		Console.WriteLine(x.tellme("What is the answer to ...?"));
	}

Access properties and call methods on CLR objects from Javascript:

	class Test
	{
		public int Value { get; set; }
		public void PrintValue(string msg)
		{
			Console.WriteLine(msg+" "+Value);
		}
	}
	
	using (var js = new JsEngine()) {
		js.SetVariable("m", new Test());
		// Sets the property from Javascript.
		js.Execute("m.Value = 42");
		// Call a method on the CLR object from Javascript. This prints:
		// "And the answer is (again!): 42"
		js.Execute("m.PrintValue('And the answer is (again!):')");
	}

Espresso-ND

Espresso-ND is special edition of the Espresso, It is NodeJS in dll form + Espresso Bridge code,

so you can run NodeJS app in-process with .NET Code

see example, run nodejs http server slide18 slide19

see how to build it at prepare/Espresso#30

espresso's People

Contributors

enginekit avatar prepare avatar fogzot avatar brezza92 avatar brezza27 avatar mikerussellnz avatar daniel15 avatar

Watchers

James Cloos avatar Clock Set Bird avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.