Server Help

ASSS Custom Projects - Invoking Mono from an ASSS Module

D1st0rt - Fri Aug 11, 2006 1:27 am
Post subject: Invoking Mono from an ASSS Module
Just a small test I did to see if I could, I was somewhat successful in running c# code from a c module.

Basically all it does when you type ?length <something> it calls a c# function contained in test.dll to get the length of the string and it returns that value to be displayed in log.

In the original mono version I had, there was a bug that caused a segfault any time you try to load the jit from a non-main thread. I updated to a more recent version and that problem was solved. The command executes fine, the only problem now is that it segfaults any time I try to destroy the jit (like in MM_UNLOAD). I'm probably doing something wrong from either end, but I don't know what it is.

For anyone that wishes to experiment, here's how I set it up (on linux):

Compile test.dll and stick it in your root asss folder
Code: Show/Hide
mcs -t:library test.cs

In the module makefile you'll also need to include the output from
Code: Show/Hide
pkg-config --cflags mono
in your cflags and
Code: Show/Hide
pkg-config --libs mono
in your ldflags

I put all of the log messages as 'E' so they would display on the screen, most of them aren't errors though.

Once its ready, insmod it and ?length something

While this is somewhat neat, I doubt it will go very far because I have absolutely no idea how to make a module loader.
Cyan~Fire - Fri Aug 11, 2006 10:14 am
Post subject:
HULK SMASH PUNY HUMAN! HULK ANGRY! HULK!

icon_sad.gif
Elnino - Fri Aug 11, 2006 10:56 am
Post subject:
Whoa that's really hawt !

Can't wait for the C# full interface =)
D1st0rt - Sat Aug 12, 2006 12:31 pm
Post subject:
If I knew enough C and ASSS to be able to write a full C# interface, I wouldn't need to write one biggrin.gif
D1st0rt - Sun Aug 13, 2006 7:39 am
Post subject:
Just an update, still haven't tracked down why it fails to clean up but I did manage to get Length() to call lm->Log() itself

cs.c
Code: Show/Hide
mono_add_internal_call("NS.MonoEmbed::Log", lm->Log);

test.cs
Code: Show/Hide
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern void Log(char filter, IntPtr msg);

public int Length(string s)
{
   string msg = "string has length of "+ s.Length;         
   MonoEmbed.Log('E', Marshal.StringToHGlobalAnsi(msg));         
   return s.Length;
}


D1st0rt> ?length how long is this string
E string has length of 23
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group