Skip to content

Instantly share code, notes, and snippets.

@ikkentim
Last active October 7, 2016 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikkentim/5f894b61cb9287bb2ddaafbe98c3a768 to your computer and use it in GitHub Desktop.
Save ikkentim/5f894b61cb9287bb2ddaafbe98c3a768 to your computer and use it in GitHub Desktop.
sampsharp natives
private class SomeNativeObject : NativeObjectSingleton<SomeNativeObject>
{
[NativeMethod("OtherNativeName")] // you can remove the parameter if FooMethod is the name of the method
public virtual int FooMethod() // must be virtual, a proxy class is generated which will implement this method
{
// lets throw this exception to indicate that the native has not properly been loaded if it has been thrown.
throw new NativeNotImplementedException();
}
[NativeMethod]
public virtual int FooMethod(out int[] things, int thingCount) // if there is an out parameter that requires a length (out string, out int[], out float[] or out bool[]) sampsharp expects the length to be the next argument
{
throw new NativeNotImplementedException();
}
[NativeMethod]
public virtual int FooMethod(out int[] things, out int[] moreThings, int thingCount, int moreThingsCount) // if there are multiple consecutive params which require lengths, sampsharp expects them to follow.
{
throw new NativeNotImplementedException();
}
[NativeMethod(3,4)] // if the native does not live up to the expectations of sampsharp, you need to specify the indices at which the lengths can be found.
public virtual int FooMethod(out int[] things, out int[] moreThings, int foobar, int thingCount, int moreThingsCount)
{
throw new NativeNotImplementedException();
}
}
// Need to access a native?
SomeNativeObject.Instance.FooMethod();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment