My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

Common Language Extension for Android

CLE is a common extension platform, which presents a general method for mixed language calls. It supports distributed object technique, which objects as medium to implement the mixed call between languages. Object is presented as a structured memory with a list of function pointers. Mixed-language calls are done by means of mapping the structured memory and function pointers to different languages, CLE is only a share library, which does not impose any restrictions on specific language. It supports windows, linux, and android.

For android version, CLE is complete free, and current version supports java in calling lua, c/c++, and python(need SL4A). CLE is very easy to use and greatly simplify the programming for java with different other languages. With the help of CLE, programmers can written c/c++ share modules without any knowledge about JNI, can call lua or python and provide callback functions of java to these languages easily.

CLE supports android version android 2.1/2.2/3.0/3.2/4.0. The install package includes a simple lua console.

wrapping android for multi-language(lua,python,c/c++) is in progress

http://code.google.com/p/wrapandroid-for-multilanguage/

Version (r6)1.5.1 is released

Changes in 1.5.1

1. add inteface functions for java, Callbool Callint Calldouble Callobject, which returns value with corresponding type;

2. add inteface functions for loading and unloading share library dynamically;

3. add inteface functions for group management, NewGroup,FreeGroup,GroupAdd,etc. Objects can be added into group and freed;

    ...
    StarNetInst.InstallZipFileDefault(this,"starcore_version.txt","http://www.srplab.com/android/starcore_armeabi_r6.zip","1.5.1.0");

or

    ...
    StarNetInst.InstallZipFileDefault(this,"starcore_version.txt","http://cle-for-android.googlecode.com/files/starcore_armeabi_r6.zip","1.5.1.0");

Version (r52)1.4.1.1 is released

    ...
    StarNetInst.InstallZipFileDefault(this,"starcore_version.txt","http://www.srplab.com/android/starcore_armeabi_r52.zip","1.4.1.1");

or

    ...
    StarNetInst.InstallZipFileDefault(this,"starcore_version.txt","http://cle-for-android.googlecode.com/files/starcore_armeabi_r52.zip","1.4.1.1");

Version (r5)1.4.1 is released

Changes in 1.4.1

1. new script function : SUnlockGC and Version;

2. new c/c++ function: DetachCurrentThread;

3. solve integer scope problem for lua script;

4. add static variable StarCoreCoreLibraryPath to starcore_android_r5.jar(for android version);

5. correct python module path for sl4a;

    ...
    StarNetInst.InstallZipFileDefault(this,"starcore_version.txt","http://www.srplab.com/android/starcore_armeabi_r5.zip","1.4.1.0");

Version (r4)1.3.1 is uploaded

Changes in 1.3.1

1. Embedded lua engine is upgraded to version 5.2

2. float type as function parameters and return value for java is supported

3. exception when free cle objects in java GC procedure is solved

4. net install function is included in starcore_android_r4.jar, you need not include starcore_netinst_r3.jar in your project from now on. The function is used as follows:

    ...
    StarNetInst.InstallZipFileDefault(this,"starcore_version.txt","http://www.srplab.com/android/starcore_armeabi_r4.zip","1.3.1.0");
    StarCoreFactoryPath.StarCoreShareLibraryPath = "/data/data/"+getPackageName()+"/files";
    StarCoreFactoryPath.StarCoreOperationPath = "/data/data/"+getPackageName()+"/files";
    ...
    starcore= StarCoreFactory.GetFactory();	
    SrvGroup = starcore._GetSrvGroup(0);

wrap of Anti-Grain Geomet Released

http://code.google.com/p/agglib-for-android/

Opengl ES2.0 2D Render Engine For Android Released

http://code.google.com/p/gles-for-android/

wrapping irrliht for android is in progress

http://code.google.com/p/wrapirrlicht-for-android/

Using CLE

First method

Install the software separately. Details is described below. This method will decrease the size of your application package. We encourage the use of this method.

Using following code to init cle

    import com.srplab.www.starcore.*;

    StarCoreFactory starcore;
    StarServiceClass Service;

    starcore= StarCoreFactory.GetFactory();		
    Service=starcore._InitSimple("test","123",0,0,"");

    ...

Second method : Using sharelib of CLE with your package

copy share libraries of cle into libs/armeabi directory of your project. As follows:

and using following code to init cle

    import com.srplab.www.starcore.*;

    StarCoreFactoryPath.InitDefault(Runtime.getRuntime(),"/data/data/com.srpgles.fishdemo");  //com.srpgles.fishdemo is your package name

    ....

    StarCoreFactory starcore;
    StarServiceClass Service;

    starcore= StarCoreFactory.GetFactory();		
    Service=starcore._InitSimple("test","123",0,0,"");

    ...

New : Install CLE files from network dynamically

Third method : Downloading sharelib of CLE dynamically

Add starcore_netinst_r3.jar to your project, as follow :

and using following code to init cle

    import com.srplab.www.starcore.*;
    import com.srplab.netinst.*;
    
    starcore_net_inst.InstallZipFile(this,"libstarcore.so","http://www.srplab.com/android/starcore_armeabi_r3.zip", "/data/data/com.cle.cfromjava/files");
    StarCoreFactoryPath.StarCoreShareLibraryPath = "/data/data/com.cle.cfromjava/files";
    StarCoreFactoryPath.StarCoreOperationPath = "/data/data/com.cle.cfromjava/files";                

    ....

    StarCoreFactory starcore;
    StarServiceClass Service;

    starcore= StarCoreFactory.GetFactory();		
    Service=starcore._InitSimple("test","123",0,0,"");

    ...

The advantage of this approach is the apk can be run on environment where cle is not installed. The activity will be restarted automatically after CLE is finished installing. You can copy starcore_armeabi_r3.zip to any website and download from there.

Permissions should be added to the project

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

Install

Install starcore_rX.apk for armeabi.

Main interface

Lua console

Programming with CLE using ecllipse

add jar of cle to project

change AndroidManifest.xml, add permissions

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

Using cle

import ….
import com.srplab.www.starcore.*;

public class XXXActivity extends Activity {
    /** Called when the activity is first created. */
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
	StarCoreFactory starcore;
	starcore= StarCoreFactory.GetFactory();
	StarServiceClass Service=starcore._InitSimple("test","123",0,0);
        …..
    }
}

Dispatching message of cle using a timer

If you want to develop a internet based distributed application, you should use a time to dispatch message of cle. As follow;

…
import com.srplab.www.starcore.*;

public class XXXActivity extends Activity {
    /** Called when the activity is first created. */
	StarCoreFactory starcore;
	Timer timer;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
	starcore= StarCoreFactory.GetFactory();
	StarServiceClass Service=starcore._InitSimple("test","123",0,0);
        
        timer = new Timer();
        final Handler handler = new Handler()  
        {  
            @Override  
            public void handleMessage(Message msg)  
            {  
                while( starcore._SRPDispatch(false) == true );
            }
        };
        timer.scheduleAtFixedRate(new TimerTask()  
        {  
            @Override  
            public void run()  
            {  
                Message mesasge = new Message();  
                mesasge.what = 0;  
                handler.sendMessage(mesasge);  
            }  
        }, 0, 10);                    
    }
}

Call lua script

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.srplab.www.starcore.*;

public class TestActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
	StarCoreFactory starcore;
	starcore= StarCoreFactory.GetFactory();
	StarServiceClass Service=starcore._InitSimple("test","123",0,0);
		
	StarSrvGroupClass SrvGroup = (StarSrvGroupClass)Service._Get("_ServiceGroup");
		
	SrvGroup._RunScript("lua","print(\"hello from lua\")","");
		
	String LuaString;		
	LuaString =             "SrvGroup = libstarcore._GetSrvGroup()\n";
	LuaString = LuaString + "Service = SrvGroup:_GetService(\"\",\"\")\n";
	LuaString = LuaString + "Obj=Service:_New(\"TestClass\");\n";
	LuaString = LuaString + "function Obj:Add(x,y)\n";
	LuaString = LuaString + "  return x+y;\n";
	LuaString = LuaString + "end\n";  
		
        Service._CheckPassword(false);
	SrvGroup._RunScript("lua",LuaString,"");
	StarObjectClass Obj = Service._GetObject("TestClass")._New();
	System.out.println(Obj._Call("Add",234,567));		
    }
}

Call python script

you should install Pythonforandroid from SL4A.

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.srplab.www.starcore.*;	

public class TestpythonActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
	StarCoreFactory starcore;
	starcore= StarCoreFactory.GetFactory();
	StarServiceClass Service=starcore._InitSimple("test","123",0,0);
		
	StarSrvGroupClass SrvGroup = (StarSrvGroupClass)Service._Get("_ServiceGroup");
		
	SrvGroup._RunScript("python","print(\"hello from python\")","");
		
	String PythonString;		
	PythonString =                   "SrvGroup = starpy._GetSrvGroup()\n";
	PythonString = PythonString + "Service = SrvGroup._GetService(\"\",\"\")\n";
	PythonString = PythonString + "Obj=Service._New(\"TestClass\");\n";
	PythonString = PythonString + "def Obj_Add(self,x,y):\n";
	PythonString = PythonString + "  return x+y;\n";
	PythonString = PythonString + "Obj.Add = Obj_Add;\n";  	
				
	Service._CheckPassword(false);
	SrvGroup._RunScript("python", PythonString,"");
	StarObjectClass Obj = Service._GetObject("TestClass")._New();
	System.out.println(Obj._Call("Add",234,567));        
    }
}

Call c sharelib

First, compile c code to sharelib using NDK.

c code:

#include "vsopenapi.h"

class ClassOfSRPInterface *SRPInterface;

static VS_INT32 Add(void *Object,VS_INT32 x,VS_INT32 y)
{
	SRPInterface ->Print("Call From android, %d,%d",x,y);
	return x + y;
}

VS_BOOL StarCoreService_Init(class ClassOfStarCore *starcore)
{
	void *AtomicClass,*Add_AtomicFunction;
	class ClassOfBasicSRPInterface *BasicSRPInterface;
	
	//--init star core
	BasicSRPInterface = starcore ->GetBasicInterface();	
	SRPInterface = BasicSRPInterface ->GetSRPInterface(BasicSRPInterface->QueryActiveService(NULL),"","");
	
	//---Create Atomic Class, for define function, no attribute 
	AtomicClass = SRPInterface ->CreateAtomicObjectSimple("TestItem","TestClass",NULL,NULL,NULL);
	Add_AtomicFunction = SRPInterface ->CreateAtomicFunctionSimple(AtomicClass,"Add","VS_INT32 Add(VS_INT32 x,VS_INT32 y);",NULL,NULL,VS_FALSE,VS_FALSE);
    //---Set Function Address
	SRPInterface -> SetAtomicFunction(Add_AtomicFunction,(void *)Add);
	return VS_TRUE;
}

void StarCoreService_Term(class ClassOfStarCore *starcore)
{
	SRPInterface -> Release();	
	return;
}

Android.mk:

LOCAL_PATH := $(call my-d
Powered by Google Project Hosting