Raised This Month: $209 Target: $400
 52% 

SharpSource


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ToXedVirus
Member
Join Date: Mar 2007
Old 09-27-2010 , 04:37   SharpSource
Reply With Quote #1

SharpSource

Short description:
SharpSource is a SourceMod extension which enables the developer to create extensions in C#. Like adding new native functions while using C#.

Status report:
This extension is currently in an early development stage, while the code is already available in order to encourage other people to participate in the development, binaries will be shipped when the extension will provide more functionality.

Currently the plugin loads managed (C#) code and loads managed assemblies, note how the arguments are all marshalled.

TODO:
  • Adjust and compliment (with helper functions) the exposed C++ interfaces for easy access
  • Create a safe subplugin system
  • Add IronRuby support
  • Add IronPython support

DONE:
  • Access C++ interfaces from within C#
  • Generate C++ wrapper classes with gccxml/a C# generator
  • Support native function creation

Credits:
The CXXI Project - an awesome C++ bindings generator for C#
Bailoplan for such a great project

Code is available at github

Some of the interfaces available in the C++ world are now available in the C# world.
I am continuing to add more and more, but I have to adjust them to make the look as native as possible.
A lot of the code is autogenerated, but the generated code needs a lot of adjustments.

Adding native functions from the C# world looks already quite awesome and easy to do:

PHP Code:
using System;
using AlliedMods;
using AlliedMods.SourceMod;
using AlliedMods.SourcePawn;

namespace 
TestSuite
{
    public class 
InteropTests IExt
    
{
        static 
int tests 0;

        public 
InteropTests()
        {
            
Core.ShareSys.AddNatives("test_addnative1", (IntPtr contextIntPtr arguments) => {
                
tests++;
                return 
1;
            });

            
Core.ShareSys.AddNatives("test_addnative2", (IPluginContext contextint[] arguments) => {
                
tests++;
                return 
2;
            });


            
Core.ShareSys.AddNatives(Core.Extensiontypeof(InteropTests));
        }

        [
SPMethod]
        public static 
void test_addnative0()
        {
        }

        [
SPMethod("test_addnative3")]
        public static 
int test_addnative3()
        {
            
tests++;
            return 
3;
        }

        [
SPMethod]
        public static 
int test_addnative4()
        {
            
tests++;
            return 
4;
        }

        [
SPMethod]
        public static 
int test_addnative5(int argument)
        {
            
tests++;
            if (
argument != 42) {
                
Console.WriteLine("failed test_addnative5");
            }
            return 
5;
        }

        [
SPMethod]
        public static 
int test_addnative6()
        {
            
tests++;
            return 
42;
        }

        [
SPMethod]
        public static 
int test_addnative7(int i)
        {
            
tests++;
            return 
i;
        }

        [
SPMethod]
        public static 
void test_end(int count)
        {
            
Console.WriteLine();
            
Console.WriteLine("tests executed {0}/{1}"testscount);
            
Console.WriteLine();
        }

        [
SPMethod]
        public static 
void test_callback(Action<SPBuffercallbackSPBuffer bufferuint maxlength)
        {
            if (
buffer.Get() != "HELLO WORLD") {
                
Console.WriteLine("FAILED");
            }

            
buffer.Set(buffer.Get().ToLower(), maxlength);
            
callback(buffer);
        }
    }

PHP Code:
#include <sourcemod>

public Plugin:myinfo =
{
  
name "SharpSource example plugin",
  
author "Andrius Bentkus",
  
description "SharpSource testing suite",
  
version "0.0.1.0",
  
url "no site available"
};

native test_addnative0();
native test_addnative1();
native test_addnative2();
native test_addnative3();
native test_addnative4();
native test_addnative5(i);
native test_addnative6();
native test_addnative7(i);
native test_end(i);

native test_callback(Function:funcString:buffer[], maxlength);

// new Function:callback = GetFunctionByName(GetMyHandle(), "callback_func");
public callback_func(String:str[])
{
  
assert(strcmp(str"hello world") == 0);
}


public 
OnPluginStart()
{
  
assert(test_addnative0() == 0);
  
assert(test_addnative1() == 1);
  
assert(test_addnative2() == 2);
  
assert(test_addnative3() == 3);
  
assert(test_addnative4() == 4);
  
assert(test_addnative5(42) == 5);
  
assert(test_addnative6() == 42);
  new 
1234;
  
assert(test_addnative7(i) == i);
  
test_end(7);
  new 
String:buffer[] = "HELLO WORLD";
  
test_callback(callback_funcbuffersizeof(buffer));


Last edited by ToXedVirus; 03-09-2012 at 08:15.
ToXedVirus is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 09-27-2010 , 07:37   Re: SharpSource
Reply With Quote #2

Interesting concept.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
Matthias Vance
Senior Member
Join Date: Jan 2009
Old 10-05-2011 , 13:09   Re: SharpSource
Reply With Quote #3

I know this is a very old thread, and only for software that will never be developed further, but I still felt the need to note this.

NOTE

Because of the nature of .NET (and Mono), loaded assemblies (plugins) cannot be unloaded, and therefore this extension will leak memory, unless they are seperated into multiple AppDomains. This is also not doable because of the huge performance hit for cross-AppDomain communication.

Quote:
Originally Posted by ToXedVirus View Post
Some people suggested that C# interoping would be very costly, therefore I created a benchmark where an empty native C++, a native C# and a simple pawn function would be called 100000000 times.
Interop is also about converting types, it gets really slow with strings.
Matthias Vance is offline
Thraka
AlliedModders Donor
Join Date: Aug 2005
Old 10-12-2011 , 19:13   Re: SharpSource
Reply With Quote #4

Damnit I got really excited too....
Thraka is offline
Matthias Vance
Senior Member
Join Date: Jan 2009
Old 10-13-2011 , 07:25   Re: SharpSource
Reply With Quote #5

You never know what the future brings. ;)
Matthias Vance is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:57.


Powered by vBulletin®
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Theme made by Freecode