freeswitch/src/mod/languages/mod_lua/freeswitch_lua.h

105 lines
2.6 KiB
C
Raw Normal View History

#ifndef FREESWITCH_LUA_H
#define FREESWITCH_LUA_H
extern "C" {
#include "lua.h"
#include <lauxlib.h>
#include <lualib.h>
#include "mod_lua_extra.h"
}
#include <switch_cpp.h>
2010-09-07 11:21:25 -05:00
#ifndef lua_pushglobaltable
#define lua_pushglobaltable(L) lua_pushvalue(L,LUA_GLOBALSINDEX)
#endif
2010-09-07 11:21:25 -05:00
typedef struct{
lua_State* L;
int idx;
}SWIGLUA_FN;
#define SWIGLUA_FN_GET(fn) {lua_pushvalue(fn.L,fn.idx);}
2018-12-15 19:03:44 +08:00
typedef struct{
lua_State* L;
int idx;
}SWIGLUA_TABLE;
#define SWIGLUA_TABLE_GET(fn) {lua_pushvalue(fn.L,fn.idx);}
2010-09-07 11:21:25 -05:00
namespace LUA {
class Session:public CoreSession {
private:
virtual void do_hangup_hook();
lua_State *getLUA();
lua_State *L;
int hh;
int mark;
public:
Session();
Session(char *uuid, CoreSession * a_leg = NULL);
Session(switch_core_session_t *session);
~Session();
SWITCH_MOD_DECLARE(virtual void) destroy(const char *err = NULL);
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
virtual void check_hangup_hook();
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
void unsetInputCallback(void);
void setInputCallback(char *cbfunc, char *funcargs = NULL);
void setHangupHook(char *func, char *arg = NULL);
bool ready();
int originate(CoreSession * a_leg_session, char *dest, int timeout);
char *cb_function;
char *cb_arg;
char *hangup_func_str;
char *hangup_func_arg;
void setLUA(lua_State * state);
};
2010-09-07 11:21:25 -05:00
class Dbh {
protected:
switch_cache_db_handle_t *dbh;
char *err;
bool m_connected;
2010-09-07 11:21:25 -05:00
static int query_callback(void *pArg, int argc, char **argv, char **cargv);
public:
Dbh(char *dsn, char *user = NULL, char *pass = NULL);
~Dbh();
bool release();
bool connected();
bool test_reactive(char *test_sql, char *drop_sql = NULL, char *reactive_sql = NULL);
2010-09-07 11:21:25 -05:00
bool query(char *sql, SWIGLUA_FN lua_fun);
2011-01-05 11:45:48 -06:00
int affected_rows();
char *last_error();
void clear_error();
int load_extension(const char *extension);
2010-09-07 11:21:25 -05:00
};
2018-12-15 19:03:44 +08:00
class JSON {
private:
bool _encode_empty_table_as_object;
bool _return_unformatted_json;
public:
JSON();
~JSON();
cJSON *decode(const char *);
char *encode(SWIGLUA_TABLE table);
cJSON *execute(const char *);
cJSON *execute(SWIGLUA_TABLE table);
char *execute2(const char *);
char *execute2(SWIGLUA_TABLE table);
void encode_empty_table_as_object(bool flag);
void return_unformatted_json(bool flag);
static int cJSON2LuaTable(lua_State *L, cJSON *json);
void LuaTable2cJSON(lua_State *L, int index, cJSON **json);
};
}
#endif