Expose Python functions to Sciter script (Interoperability)
masterTo allow TIScript or JavaScript to call Python code, define a dictionary of Python functions (or lambdas) and return it from a function that is called by the Sciter EventHandler.on_script_call.
Python Implementation
def GetNativeApi():
def on_add(a, b):
return a + b
def on_sub(a, b):
raise Exception("sub(%d,%d) raised exception" % (a, b))
api = {
'add': on_add,
'sub': on_sub,
'mul': lambda a, b: a * b
}
return apiAccessing from TIScript
var api = view.GetNativeApi();
stdout.println("2 + 3 = " + api.add(2, 3));Accessing from JavaScript
const api = Window.this.GetNativeApi();
console.log("2 + 3", api.add(2, 3));def GetNativeApi():
def on_add(a, b):
return a + b
def on_sub(a, b):
raise Exception("sub(%d,%d) raised exception" % (a, b))
api = { 'add': on_add,
'sub': on_sub,
'mul': lambda a,b: a * b }
return api
# In JS:
const api = Window.this.GetNativeApi();
console.log("2 + 3", api.add(2, 3));