0

I try to convert sample .net application with P/Invoke to javascript with JSIL.

C# code:

[DllImport("JSTestLib", EntryPoint = "Get42", CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern int Get42();

Generated javascript:

$.ExternalMethod({Static:true , Public:true }, "Get42", 
  JSIL.MethodSignature.Return($.Int32)
);

Where should I add implementation of the Get42 method in javascript? Should I register this method manually in JSIL?

I have only an error now:

The external method 'System.Int32 Get42()' of type 'Test.Program' has not been implemented.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Vladimir Vlasov
  • 1,860
  • 3
  • 25
  • 38
  • jsil transform to javascript only MSIL command, but when you use P/Invoke, MSIL does not contain code for external function, so JSIL transform only declaration – Grundy Nov 14 '14 at 20:02
  • I know, that's only the declaration. I don't know where I have to place the implementation. – Vladimir Vlasov Nov 14 '14 at 20:10
  • if you have implementation, why you use extern? just add implementation to you function, also you can see about [verbatim javascript](http://jsil.org/#samples/verbatim.html) – Grundy Nov 14 '14 at 20:45
  • I ask, because I want translate to javascript native lib too (on C++). With Emscripten for example. – Vladimir Vlasov Nov 15 '14 at 05:24

1 Answers1

1

Just use JSIL.ImplementExternals - take a look at JSIL.Core.js for examples

matra
  • 9,763
  • 4
  • 20
  • 31