GithubHelp home page GithubHelp logo

redchew-fork / monoexport Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ibilon/monoexport

0.0 0.0 0.0 6 KB

Generate code used to launch a haxe executable from a c++ application

License: MIT License

Haxe 98.00% C++ 2.00%

monoexport's Introduction

MonoExport

Generate code used to launch a haxe executable from a c++ application, using the mono runtime.

Annoted classes will have their static functions made available to c++.

The haxe "world" is not reset between calls, so you can store data in static variables, see the example for more details.

Install

You can do either haxelib install monoexport or haxelib git monoexport https://github.com/ibilon/MonoExport.git.

Usage

Haxe

Add -lib monoexport to you hxml, and annotate the classes that should be exported with @:monoExport.

You can configure the name of the generated c++ files with -D monoexport-out=filename.

You can also configure the name used in the include statement of the cpp file with -D monoexport-include=filename.

The following types are supported in argument/return values:

  • Bool
  • Int
  • Float
  • String
  • Array<Bool>
  • Array<Int>
  • Array<Float>
  • Array<String>

C++

You need to compile with the mono runtime, you can find the required flags on linux with pkg-config --cflags --libs mono-2.

You just need to include the generated c++ file, init with MonoExport::init("path/to/haxe/cs.dll"); (Note: the dll will be named cs-Debug.dll when doing a debug build) and you can call haxe functions using the following syntax: MonoExport::HaxeClassName::functionname();.

Don't forget to clean the mono runtime at the end MonoExport::clean();.

Example

You can find this example in the example/ folder.

@:monoExport
class MyHaxeClass {
	static var first:Bool = true;
	public static function sayHello(name:String) {
		trace("Hello" + (first ? " " : " again ") + name + "!");
		first = false;
	}
}

Compile it with haxe MyHaxeClass -lib monoexport -cs output, or optionally haxe MyHaxeClass -lib monoexport -cs output -D monoexport-out=custom.

#include "MonoExport.hpp"

int main() {
	MonoExport::init("output/bin/output.dll");
	MonoExport::MyHaxeClass::sayHello("John");
	MonoExport::MyHaxeClass::sayHello("John");
	MonoExport::clean();
}

If you used a custom output filename change the include to "custom.hpp"

Compile it (on linux) with g++ MonoExport.cpp main.cpp $(pkg-config --cflags --libs mono-2) -o host. Adapt the first cpp filename to custom.cpp in case of custom output filename.

Running it, ./host, will print:

MyHaxeClass.hx:5: Hello John!
MyHaxeClass.hx:5: Hello again John!

License

The code is licensed under the MIT license.

monoexport's People

Contributors

ibilon 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.