一.创建Session
在lua中通过调用 freeswitch.Session()可以创建一个Session对象。按源码里的注释,他包括四个原型:
LUA::Session::Session()
LUA::Session::Session(char ,CoreSession )
LUA::Session::Session(char *)
LUA::Session::Session(switch_core_session_t *)
所以他有四个初始化的方式。
mod_lua_wrap.cpp这个文件主要是将C++的函数接口封装成lua接口,在这里面:
static swig_lua_class _wrap_class_LUA_Session = { "Session", &SWIGTYPE_p_LUA__Session,_wrap_new_Session, swig_delete_Session, swig_LUA_Session_methods, swig_LUA_Session_attributes, { "Session", swig_LUA_Session_cls_methods, swig_LUA_Session_cls_attributes, swig_LUA_Session_cls_constants }, swig_LUA_Session_bases, swig_LUA_Session_base_names };
创建了一个swig_lua_class
typedef struct swig_lua_class {
const char *name;
swig_type_info **type;
lua_CFunction constructor;
void (*destructor)(void *);
swig_lua_method *methods;
swig_lua_attribute *attributes;
struct swig_lua_class **bases;
const char **base_names;
} swig_lua_class;
这个是表示一个注册lua对象的结构体。其实就是通过注册一个个swig_lua_class,使得lua脚本可以想调用对象一样调用C++里面的对象的方法。
name 是在lua中的名字
constructor 可以理解为构造函数
destructor 自然是析构函数
methods 这个对象的方法
attributes这个对象的属性
所以构造函数是:_wrap_new_Session()也是在执行freeswitch.Session的时候会调用_wrap_new_Session()这个函数。
static int _wrap_new_Session(lua_State* L) {
int argc;
int argv[3]={
1,2,3
};
argc = lua_gettop(L);
if (argc == 0) {
return _wrap_new_Session__SWIG_0(L);
}
if (argc == 1) {
int _v;
{
void *ptr;
if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_switch_core_session_t, 0)) {
_v = 0;
} else {
_v = 1;
}
}
if (_v) {
return _wrap_new_Session__SWIG_3(L);
}
}
if (argc == 1) {
int _v;
{
_v = SWIG_lua_isnilstring(L,argv[0]);
}
if (_v) {
return _wrap_new_Session__SWIG_2(L);
}
}
if (argc == 2) {
int _v;
{
_v = SWIG_lua_isnilstring(L,argv[0]);
}
if (_v) {
{
void *ptr;
if (SWIG_isptrtype(L,argv[1])==0 || SWIG_ConvertPtr(L,argv[1], (void **) &ptr, SWIGTYPE_p_CoreSession, 0)) {
_v = 0;
} else {
_v = 1;
}
}
if (_v) {
return _wrap_new_Session__SWIG_1(L);
}
}
}
SWIG_Lua_pusherrstring(L,"Wrong arguments for overloaded function 'new_Session'\n"
" Possible C/C++ prototypes are:\n"
" LUA::Session::Session()\n"
" LUA::Session::Session(char *,CoreSession *)