Support C UDF

Currently Aerospike support Lua UDF. How about to support C UDF? So people sensitive to performance can write C UDF (with .so lib).

Aerospike does provide means of calling a C module via a thin Lua binding. .so can be registered and used similarly as Lua files.

Please check out as a starter. http://www.aerospike.com/docs/udf/developing_lua_modules.html

Will also add more detail here soon.

The sample C file addition.c could be something like this.


static int c_add(lua_State *L){              /* Internal name of func */`
lua_Integer num1 = luaL_optinteger(L, 1,0);      /* Get the single number arg */
    lua_Integer num2 = luaL_optinteger(L, 2, 0); 
    int sum = num1 + num2;
    lua_pushinteger(L, sum);           /* Push the return */
    return 1;                              /* One return value */
}

int luaopen_addition(lua_State *L){
    lua_register(L, "lua_add",c_add); 
    return 0;
}

This can be compiled to a shared library addition.so using


gcc -Wall -shared -fPIC -o addition.so  -I/usr/include/lua5.1 -llua5.1  addition.c 

The addition.so could be invoked in a lua file.



local addition = require("addition")

local function addValue(var1, var2)
    return lua_add(var1, var2)
end

function recCreate(rec)
    rec['foo'] = 123 
    rec['bar'] = 123 
    return aerospike:create(rec)
end

function recUpdate( rec )
    rec['foobar'] = addValue(rec['foo'], rec['bar'])
    return aerospike:update(rec)
end

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.