![]() |
Common Language Extension(CLE) |
|||
For lua calls java, 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 call lua 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”.
import com.srplab.www.starcore.*;
//--Step2 : Define extends class of
StarObjectClass, and defines a new function “Add” of it.
class MyObjectClass extends 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)
{
super(srcobj);
}
}
public class AddFunctionService{
public
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 lua code calls the above java, there are three steps; 1. Init cle, create service group,import java, and create service. 2. Create Instance of object “TestClass” defined in java. 3. Call function “Add”.
require "libstarcore"
--Step 1 : Init cle, create service
group,import java, and create
service.
Service=libstarcore._InitSimple("test","123",0,0,"AddFunctionService.class?script=java");
--Step 2: Create Instance of object “TestClass”
defined in java.
a = Service.TestClass:_New();
--Step 3: call function “Add”
function a:Show(
print("print from lua call back "..
end
print("Add returns : "..a:Add(12,34))
Service._ServiceGroup:_ClearService()
libstarcore._ModuleExit()
Run : starapp -e lua_call.lua |
| examples code download |
| Copywright (C) 2005 www.SRPLab.com(Star-River Platform Lab.) All Rights Reserved | Email:support@srplab.com |