srplab Common Language Extension(CLE)
 

For php calls c#, here presents a new method, which ues cle developed by srplab..A function “Add” is defined in lua which returns the sum of two input integers. The function also calls php method “Show” to print the result.

There are three steps:

1.       Init cle, create service group, and create service.

2.       Define extends class of StarObjectClass, and defines a new function “Add” of it.

3.       Create interface object, named “TestClass”.

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using star_csharp;

 

namespace AddFunctionService

{

//--Step2 : Define extends class of StarObjectClass, and defines a new function “Add” of it.

    class MyObjectClass : StarObjectClass

    {

        public int Add(StarObjectClass self, int x, int y)

        {

//--Callback to script function

            self._Call("Show", x + y);

            return x + y;

        }

        public MyObjectClass(StarObjectClass srcobj)

            : base(srcobj)

        {

        }

    }

    class Program

    {

        static void Main (string[] args)

        {

        //--Step1 : Init cle, create service group,import sharelibrary,  and create service

            StarCoreFactory starcore = StarCoreFactory.GetFactory();

            StarServiceClass Service = starcore._InitSimple("AddFunctionService", "123", 0, 0);

              //--Step3 : Create interface object, named “TestClass”.

            MyObjectClass Obj = new MyObjectClass(Service._New("TestClass"));

        }

    }

}

 

For php code calls the above c# file, there are three steps;

1.       Init cle, create service group,import c# file,  and create service.

2.       Create Instance of object “TestClass” defined in c#.

3.       Call function “Add”.

 

<?php

   Step 1 : Init cle, create service group,import c# file,  and create service.

   $starcore = new StarCoreFactory();

   $Service=$starcore->_InitSimple("test","123",0,0," AddFunctionService.exe?script=csharp");

   Step 2: Create Instance of object “TestClass” defined in c#.

   $a = $Service->TestClass->_New();

   function a_Show($self,$Para)

   {

       echo "from php call back"  ,$Para,"\n";

   }

   $a -> Show = "a_Show";

   Step 3: call function “Add”

   $Result = $a->Add(12,34);

   echo "Add returns : ",$Result,"\n";

   $Service->_ServiceGroup->_ClearService();

   $starcore->_ModuleExit();

?>  

 

Run : php –f php_call.php

examples code download

Copywright (C) 2005 www.SRPLab.com(Star-River Platform Lab.) All Rights Reserved Email:support@srplab.com