GithubHelp home page GithubHelp logo

mono.embedding's Introduction

Mono.Embedding

ThunkTool

This utility is generating C/C++ source code from an assembly which contains Thunk attributes.

When applied to members, Thunk attributes (see ThunkAttribute class) are instrucing ThunkTool to generate C/C++ callable thunks from these members.

The ThunkAttribute class can (and should) be included inline in the assembly because ThunkTool is looking for this attribute by name.

What does the tool generate?

  • Thunks for all members marked with [Thunk]

  • Initialization function for the assembly:

    $(Assembly_Name)_Init((MonoAssembly *assembly);

  • Function which invokes the Main() entry point of an assembly:

    $(Assembly_Name)_Exec(void);

Usage

mono ThunkTool.exe --output prefix [--comments] assembly.{dll|exe}

The output will be stored into prefix.c and prefix.h.

Example

Input code

// C##
// assembly foo.dll
namespace Foo {
  public class ExportMe {
    [Thunk]
    public int Method() { ... }

    [Thunk]
    public string Property { get { ... } }   

    // emit a more specific type than intptr    
    [Thunk (ReturnType = "MonoType *")]
    public IntPtr GetTypeHandle(Type t)
    {
        return t.TypeHandle.Value;
    }
    
    // assembly entry point
    static void Main ()
    {
    }
  }
}

Invoke ThunkTool

mono ThunkTool.exe --output=foo foo.dll

Generated C/C++ header

// `foo.h`
...
MonoClass *ExportMe__Class;   // Foo.ExportMe class
int32_t (THUNKCALL *ExportMe_Method)(MonoObject **ex);
MonoString* (THUNKCALL *ExportMe_get_Property)(MonoObject **ex);
...

MonoAssembly *Foo_Assembly;
MonoImage *Foo_Image;

// initalization function.
void Foo_Init (MonoAssembly *assembly);

// invokes the entry point of the assembly
void Foo_Exec (void);

In your own C++ code you should include the header, initialize the Mono runtime, load the assembly and pass it to $(Assembly_Name)_Init () function. After that, all members attributed with [Thunk] are available for invocation. Additionally, all involved classes are available as $(Assembly_Name)_$(ClassName)__Class variables.

mono.embedding's People

Contributors

migueldeicaza avatar robert-j avatar thesaurus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

mono.embedding's Issues

UniversalDelegate serialisation

Turns out I need to serialise a UniversalDelegate in order to pass it between domains. The current implementation implodes (even if the wrapper classes are marked as serialisable) because (I think) the dynamic classes used to contain the invocation lambdas are not themselves serialisable.

I have played around with this in a branch https://github.com/ThesaurusSoftware/Mono.Embedding/tree/serializable-action-wrappers

and commits like this

brightsg@203129b

Seems to work okay but it's more verbose than using the lambdas. I haven't update the code gen script yet.

Is there a better way?

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.