Raised This Month: $51 Target: $400
 12% 

SharpSource


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
ToXedVirus
Member
Join Date: Mar 2007
Old 09-27-2010 , 03: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 07:15.
ToXedVirus is offline
 



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 00:27.


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