srplab Common Language Extension(CLE)
 

For lua calls python, 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.       Create interface object, and defines a new function “Add” of it.

3.       Write function code of Add.

 

import starpy

--Step1 : Init cle, create service group, and create service

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

--Step2 : Create interface object, and define function Add

Obj=Service._New("TestClass");

--Step3 : Add function code

def Obj_Add(self,x,y) :

  --call back to script function

  self.Show(x+y);

  return x+y;

Obj.Add = Obj_Add;

 

For lua code calls the above python file, there are three steps;

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

2.       Create Instance of object “TestClass” defined in python.

3.       Call function “Add”.

 

require "libstarcore"

--Step 1 : Init cle, create service group,import python,  and create service.

Service=libstarcore._InitSimple("test","123",0,0," AddFunctionService.py?script=python");

--Step 2: Create Instance of object “TestClass” defined in python.

a = Service.TestClass:_New();

--Step 3: call function “Add”

function a:Show( Para )

    print("print from lua call back ".. Para )

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