如何在Tarantool中从SQL调用C函数?

问题描述

如何在Tarantool中从sql调用C函数

jaeger-all-in-one with memory说:

C函数是从.so文件导入的

但是我应该在哪里指定对我的.so文件的引用?

很高兴看到一个例子。

解决方法

您首先应该通过:func.create注册功能:

box.schema.func.create("function1.divide",{language = 'C',returns = 'number',is_deterministic = true,exports = {'LUA','SQL'}})

您可以在此处阅读有关主题的更多信息:https://www.tarantool.io/en/doc/latest/tutorials/c_tutorial/

然后您可以在SQL中使用它:

box.execute('SELECT "function1.divide"()')

您还可以查看源代码(test/box/function1.test.lua)中的更多示例。