![]() |
Common Language Extension(CLE) |
|||
For python calls lua, 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 python method “Show” to print the result. There are three steps: 1. Init cle, create service group, and create service. 2. Create interface object, and defines a new function “Add” of it. 3. Write function code of Add.
require "libstarcore"
--Step1 : Init cle, create service group,
and create service
Service =
libstarcore._InitSimple("AddFunctionService","123",0,0);
--Step2 : Create interface object, and
define function Add
Obj=Service:_New("TestClass");
--Step3 : Add function code
function Obj:Add(x,y)
--call back to script function
self:Show(x+y);
return
x+y;
end
For python code calls the above lua file, there are three steps; 1. Init cle, create service group,import lua code, and create service. 2. Create Instance of object “TestClass” defined in sharelibrary. 3. Call function “Add”.
import starpy
--Step 1 : Init cle, create service
group,import lua file, and create
service.
Service=starpy._InitSimple("test","123",0,0,"AddFunctionService.dll");
--Step 2: Create Instance of object “TestClass”
defined in lua.
a = Service.TestClass._New();
--Step 3: call function “Add”
def a_Show(self,
print("print from python call back ",
a.Show = a_Show;
print("Add returns : ",a.Add(12,34))
Service._ServiceGroup._ClearService()
starpy._ModuleExit()
Run : starapp -e python_call.py?script=python, or python python_call.py |
| examples code download |
| Copywright (C) 2005 www.SRPLab.com(Star-River Platform Lab.) All Rights Reserved | Email:support@srplab.com |