Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dbh query with params for FS
%module freeswitch
%{
#include "freeswitch_lua.h"
%}
%typemap(in, checkfn = "lua_isfunction") SWIGLUA_FN {
$1.L = L;
$1.idx = $input;
}
%typemap(default) SWIGLUA_FN {
SWIGLUA_FN default_swiglua_fn = { 0 };
$1 = default_swiglua_fn;
}
%typemap(typecheck) SWIGLUA_FN {
$1 = lua_isfunction(L, $input);
}
%typemap(in, checkfn = "lua_istable") SWIGLUA_TABLE {
$1.L = L;
$1.idx = $input;
}
%typemap(default) SWIGLUA_TABLE {
SWIGLUA_TABLE default_swiglua_table = { 0 };
$1 = default_swiglua_table;
}
%typemap(typecheck) SWIGLUA_TABLE {
$1 = lua_istable(L, $input);
}
class Dbh {
public:
Dbh(char *dsn, char *user = NULL, char *pass = NULL);
bool query(char *sql, SWIGLUA_FN lua_fun);
bool query(char *sql, SWIGLUA_TABLE lua_params);
bool query(char *sql, SWIGLUA_TABLE lua_params, SWIGLUA_FN lua_fun);
};
dbh:query('1'); -- bool query(char *sql, SWIGLUA_FN lua_fun);
dbh:query('2', {}) -- bool query(char *sql, SWIGLUA_TABLE lua_params);
dbh:query('3', {}, function() end) -- bool query(char *sql, SWIGLUA_TABLE lua_params, SWIGLUA_FN lua_fun);
dbh:query('4', function() end) -- bool query(char *sql, SWIGLUA_FN lua_fun);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.