Added char.
[mono.git] / docs / internal-calls
1
2 * How to map C# types for use in the C implementation of internal calls
3
4         C# type         C type
5         char            gunichar2
6         bool            MonoBoolean
7         sbyte           signed char
8         byte            guchar
9         short           gint16
10         ushort          guint16
11         int             gint32
12         uint            guint32
13         long            gint64
14         ulong           guint64
15         IntPtr/UIntPtr  gpointer
16         object          MonoObject*
17         string          MonoString*
18
19 For ref and out paramaters you'll use the corresponding pointer type.
20 Arrays of any type must be described with a MonoArray* and the elements 
21 must be accessed with the mono_array_* macros.
22 Any other type that has a matching C structure representation, should use
23 a pointer to the struct instead of a generic MonoObject pointer.
24
25 Instance methods that are internal calls will receive as first argument
26 the instance object, so you must account for it in the C method signature:
27
28         [MethodImplAttribute(MethodImplOptions.InternalCall)]
29         public extern override int GetHashCode ();
30
31 becaomes:
32
33         gint32 ves_icall_System_String_GetHashCode (MonoString *this);
34
35
36
37 * How to hook internal calls with the runtime
38
39 Once you require an internal call in corlib, you need to create a C
40 implementation for it and register it in a static table in metadata/icall.c.
41 Add an entry in the table like:
42
43         "System.String::GetHashCode", ves_icall_System_String_GetHashCode,
44
45 Note that you need to include the full namespace.name of the class.
46 If there are overloaded methods, you need also to specify the signature
47 of _all_ of them:
48
49         [MethodImplAttribute(MethodImplOptions.InternalCall)]
50         public extern override void DoSomething ();
51         [MethodImplAttribute(MethodImplOptions.InternalCall)]
52         public extern override void DoSomething (bool useful);
53
54 should be mapped with:
55
56         "Namespace.ClassName::DoSomething()", ves_icall_Namespace_ClassName_DoSomething,
57         "Namespace.ClassName::DoSomething(bool)", ves_icall_Namespace_ClassName_DoSomething_bool,
58
59