示例#1
0
文件: glue.cpp 项目: Chaduke/bah.mod
void bmx_roomquery_AddQuery_STRING(RakNet::RoomQuery * query, BBString * columnName, BBString * charValue, int op) {
	char * c = bbStringToCString(columnName);
	char * v = bbStringToCString(charValue);
	query->AddQuery_STRING(c, v, static_cast<DataStructures::Table::FilterQueryType>(op));
	bbMemFree(c);
	bbMemFree(v);
}
示例#2
0
/* Internal
  Places the offset of an instance variable for a class into the global list of glue info
  An exception is thrown if you pass a NULL pointer for the class
*/
void p_lugi_register_field(int offset, int type, BBString *name, BBClass *clas) {
    if ( clas == NULL )
        bbExThrowCString(ERRORSTR("@lugi_register_field: Cannot pass Null BBClass for field."));
    glueinfo_t *info;
    char *cname = bbStringToCString(name);

    info = lugi_g_infohead;
    while (info != NULL) {
        if ( info->type == FIELDTYPE && info->clas == clas &&
                strcmp(cname, info->name) == 0 && info->data.field.offset == offset &&
                info->data.field.type == type ) {
            // then
            bbMemFree(cname);
            return;
        }

        info = info->next;
    }


    info = (glueinfo_t*)bbMemAlloc(sizeof(glueinfo_t));
    info->type = FIELDTYPE;
    info->data.field.offset = static_cast<ptrdiff_t>(offset);
    info->data.field.type = static_cast<fieldtype_e>(type);
    info->clas = clas;
    info->name = cname;
    info->next = lugi_g_infohead;
    lugi_g_infohead = info;
}
示例#3
0
文件: glue.cpp 项目: GWRon/wx.mod
int bmx_wxiobase_open(wxIOBase * base, BBString * deviceName, void * dcs) {
	char * p = bbStringToCString( deviceName );
	int ret = base->Open(p, dcs);
	
	bbMemFree( p );
	return ret;
}
示例#4
0
文件: glue.cpp 项目: Chaduke/bah.mod
BBString * bmx_gme_open_file( MaxMusicEmu * emu, BBString * path, long sample_rate) {

	char *p = bbStringToCString( path );
	BBString * ret = bbStringFromCString(gme_open_file(p, &emu->emu, sample_rate));
	bbMemFree( p );
	
	return ret;
}
示例#5
0
XML_Parser bmx_expat_XML_ParserCreate(BBString * encoding) {
	char * c = NULL;
	if (encoding != &bbEmptyString) {
		c = bbStringToCString(encoding);
	}
	
	XML_Parser parser = XML_ParserCreate(c);
	
	if (c) bbMemFree(c);
	
	return parser;
}
示例#6
0
文件: glue.cpp 项目: GWRon/wx.mod
int bmx_wxiobase_readuntileos(wxIOBase * base, char * buffer, int * bytesRead, BBString * eos, int timeout, int quota) {
	char * p = bbStringToCString( eos );
	char * newbuff = NULL;
	
	size_t size;
	int ret = base->ReadUntilEOS(newbuff, &size, p, timeout, static_cast<char>(quota));
	*bytesRead = static_cast<int>(size);
	
	if (bytesRead > 0) {
		memcpy(buffer, newbuff, size);
	}
	delete newbuff;

	bbMemFree( p );
	return ret;
}
示例#7
0
文件: glue.cpp 项目: Chaduke/bah.mod
BBString * _formatDate(BBString * format, int y, int m, int d, int hh, int mm, int ss) {

	char buffer [1024];
	tm stm;
	char * p = bbStringToCString(format);

	stm.tm_year = y - 1900;
	stm.tm_mon = m - 1;
	stm.tm_mday = d;
	stm.tm_hour = hh;
	stm.tm_min = mm;
	stm.tm_sec = ss;

	strftime (buffer, 1024, p, &stm);
	
	bbMemFree(p);
	
	return bbStringFromCString(buffer);
}
示例#8
0
文件: glue.cpp 项目: Chaduke/bah.mod
BBString * bmx_profanityfilter_FilterProfanity(ProfanityFilter * filter, BBString * text, int f, int * ret) {
	char * t = bbStringToCString(text);

	char * output = 0;
	if (filter) {
		output = (char *) malloc(strlen(t) + 1);
	}
	
	*ret = filter->FilterProfanity(t, output, static_cast<bool>(f));
	
	bbMemFree(t);
	
	BBString * o = 0;
	if (output) {
		o = bbStringFromCString(output);
		free(output);
	} else {
		o = text;
	}
	
	return o;
}
示例#9
0
/* Internal
  Places a glue function with the name specified into the global list of glue info
  If it's a method of a class, pass a pointer to the object's BBClass to insert it into
  the class's Lua method table
  If you're registering a global function (e.g., just a regular glue function), pass a NULL pointer
  for the class
*/
void p_lugi_register_method(lua_CFunction fn, BBString *name, BBClass *clas) {
    glueinfo_t *info;
    char *cname = bbStringToCString(name);

    info = lugi_g_infohead;
    while (info != NULL) {
        if ( info->type == METHODTYPE && info->clas == clas &&
                strcmp(cname, info->name) == 0 && info->data.fn == fn ) {
            // then
            bbMemFree(cname);
            return;
        }

        info = info->next;
    }

    info = (glueinfo_t*)bbMemAlloc(sizeof(glueinfo_t));
    info->type = METHODTYPE;
    info->data.fn = fn;
    info->clas = clas;
    info->name = cname;
    info->next = lugi_g_infohead;
    lugi_g_infohead = info;
}
示例#10
0
文件: glue.cpp 项目: Chaduke/bah.mod
void bmx_roomquery_AddQuery_NUMERIC(RakNet::RoomQuery * query, BBString * columnName, double numericValue, int op) {
	char * c = bbStringToCString(columnName);
	query->AddQuery_NUMERIC(c, numericValue, static_cast<DataStructures::Table::FilterQueryType>(op));
	bbMemFree(c);
}
示例#11
0
static const char *appTitleA(){
	return bbStringToCString( bbAppTitle );
}
示例#12
0
文件: glue.cpp 项目: Chaduke/bah.mod
void bmx_profanityfilter_AddWord(ProfanityFilter * filter, BBString * newWord) {
	char * w = bbStringToCString(newWord);
	filter->AddWord(w);
	bbMemFree(w);
}
示例#13
0
文件: glue.cpp 项目: Chaduke/bah.mod
void bmx_chatfunc_SetPrivateMessageRecipient(RakNet::Chat_Func * func, BBString * name) {
	char * n = bbStringToCString(name);
	func->privateMessageRecipient = n;
	bbMemFree(n);
}
示例#14
0
BBGLContext *bbGLGraphicsCreateGraphics( int width,int height,int depth,int hertz,int flags, int x, int y ){
	BBGLContext *context;
	
	int mode;
	HDC hdc;
	HWND hwnd;
	HGLRC hglrc;
	
	long pf;
	PIXELFORMATDESCRIPTOR pfd;
	int hwnd_style;
	RECT rect={0,0,width,height};
	
	_initWndClass();
	
	if( depth ){
		mode=MODE_DISPLAY;
		hwnd_style=WS_POPUP;
	}else{
		HWND desktop = GetDesktopWindow();
		RECT desktopRect;
		GetWindowRect(desktop, &desktopRect);

		rect.left=(x == -1) ? desktopRect.right/2-width/2 : x + GetSystemMetrics(SM_CXBORDER);
		rect.top=(y == -1) ? desktopRect.bottom/2-height/2: y + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFIXEDFRAME);
		rect.right=rect.left+width;
		rect.bottom=rect.top+height;
		
		mode=MODE_WINDOW;
		hwnd_style=WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX;
	}
		
	AdjustWindowRectEx( &rect,hwnd_style,0,0 );
	
	if( _bbusew ){
		BBChar *p=bbStringToWString( bbAppTitle );
		hwnd=CreateWindowExW( 
			0,CLASS_NAMEW,p,
			hwnd_style,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,0,0,GetModuleHandle(0),0 );
		bbMemFree(p);
	}else{
		char *p=bbStringToCString( bbAppTitle );
		hwnd=CreateWindowEx( 
			0,CLASS_NAME,p,
			hwnd_style,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,0,0,GetModuleHandle(0),0 );
		bbMemFree(p);
	}
		
	if( !hwnd ) return 0;

	GetClientRect( hwnd,&rect );
	width=rect.right-rect.left;
	height=rect.bottom-rect.top;
		
	_initPfd( &pfd,flags );

	hdc=GetDC( hwnd );
	int multisample = 0;
	if (_MULTISAMPLE2X & flags) multisample = 2;
	else if (_MULTISAMPLE4X & flags) multisample = 4;
	else if (_MULTISAMPLE8X & flags) multisample = 8;
	else if (_MULTISAMPLE16X & flags) multisample = 16;
	if (multisample>0){
		pf=MyChoosePixelFormat( hdc,flags );
	}else{
		pf=ChoosePixelFormat( hdc,&pfd );
	}
	if( !pf ){
		DestroyWindow( hwnd );
		return 0;
	}
	SetPixelFormat( hdc,pf,&pfd );
	hglrc=wglCreateContext( hdc );
	
	if( _sharedContext ) wglShareLists( _sharedContext->hglrc,hglrc );
	
	context=(BBGLContext*)malloc( sizeof(BBGLContext) );
	memset( context,0,sizeof(context) );
	
	context->mode=mode;
	context->width=width;
	context->height=height;
	context->depth=depth;
	context->hertz=hertz;
	context->flags=flags;
	
	context->hdc=hdc;
	context->hwnd=hwnd;
	context->hglrc=hglrc;
	
	context->succ=_contexts;
	_contexts=context;
	
	ShowWindow( hwnd,SW_SHOW );
	
	return context;
}
示例#15
0
文件: glue.cpp 项目: Chaduke/bah.mod
int bmx_profanityfilter_HasProfanity(ProfanityFilter * filter, BBString * text) {
	char * t = bbStringToCString(text);
	int ret = static_cast<int>(filter->HasProfanity(t));
	bbMemFree(t);
	return ret;
}
示例#16
0
文件: glue.cpp 项目: Chaduke/bah.mod
int bmx_allgamesroomcontainer_addtitle(RakNet::AllGamesRoomsContainer * rc, BBString * gameIdentifier) {
	char * g = bbStringToCString(gameIdentifier);
	int ret = rc->AddTitle(g);
	bbMemFree(g);
	return ret;
}
示例#17
0
文件: glue.cpp 项目: Chaduke/bah.mod
void bmx_joinbyfilterfunc_SetGameIdentifer(RakNet::JoinByFilter_Func * func, BBString * gameIdentifier) {
	char * n = bbStringToCString(gameIdentifier);
	func->gameIdentifier = n;
	bbMemFree(n);
}
示例#18
0
文件: glue.cpp 项目: Chaduke/bah.mod
void bmx_enterroomfunc_SetGameIdentifer(RakNet::EnterRoom_Func * func, BBString * gameIdentifier) {
	char * n = bbStringToCString(gameIdentifier);
	func->gameIdentifier = n;
	bbMemFree(n);
}
示例#19
0
文件: glue.cpp 项目: Chaduke/bah.mod
void bmx_networkedroomcreationparameters_SetRoomName(RakNet::NetworkedRoomCreationParameters * param, BBString * name) {
	char * n = bbStringToCString(name);
	param->roomName = n;
	bbMemFree(n);
}
示例#20
0
文件: glue.cpp 项目: Chaduke/bah.mod
void bmx_roomspluginfunc_setusername(RakNet::RoomsPluginFunc * func, BBString * name) {
	char * n = bbStringToCString(name);
	func->userName = n;
	bbMemFree(n);
}
示例#21
0
/* precondition: lua interface must be initialized for this state, or you will experience a crash. */
void lua_pushbmaxobject(lua_State *state, BBObject *obj) {
    int top = lua_gettop(state);

    if (obj == &bbNullObject || (BBArray*)obj == &bbEmptyArray) {
        lua_pushnil(state);
        return;
    }
    else if ((BBString*)obj == &bbEmptyString) {
        lua_pushlstring(state, "", 0);
        return;
    }

    if (obj->clas == &bbStringClass) {
        BBString *str = (BBString*)obj;
        char *buf = bbStringToCString(str);
        lua_pushlstring(state, buf, str->length);
        bbMemFree(buf);
        return;
    }

    /* check object cache for existing object */
    lua_pushlightuserdata(state, LUGI_OBJECT_CACHE_KEY);
    lua_gettable(state, LUA_REGISTRYINDEX);

    /* cache[object] */
    lua_pushlightuserdata(state, obj);
    lua_gettable(state, -2);

    /* if cache[object] == object */
    if (lua_type(state, -1) == LUA_TUSERDATA) {
        lua_remove(state, -2);
        /* object exists, remove table and return */
        return;
    }

    lua_pop(state, 1);

    /* increment reference count for the object since BMax's default GC relies on ref counting */
    BBRETAIN(obj);

    /* store object */
    BBObject **data = (BBObject**)lua_newuserdata(state, sizeof(BBObject*));
    *data = obj;

#if BMX_TABLE_SUPPORT > 0
    /*
      this is part of an unsupported feature to enable table-like behavior for BMax objects
      decided not to include it (by default, anyway) because, frankly, it doesn't fit in when
      you might be trying to set a field for some reason and you'll never receive an error
      that the field doesn't exist because you're just setting some value for a table
    */
    lua_newtable(state);
    if ( lua_setfenv(state, -2) == 0 )
    {
        lua_settop(state, top); /* clean up stack.. */
        luaL_error(state, ERRORSTR("@lua_pushbmaxobject: Failed to set environment table for BMax object."));
        return;
    }
#endif

    /* set the metatable */
    if ( obj->clas == &bbArrayClass )
        lua_pushlightuserdata(state, LUGI_METATABLE_ARRAY_KEY);
    else
        lua_pushlightuserdata(state, LUGI_METATABLE_KEY);

    lua_gettable(state, LUA_REGISTRYINDEX);
    lua_setmetatable(state, -2);

    /* cache the object and remove the cache table */
    lua_pushlightuserdata(state, obj);
    lua_pushvalue(state, -2);
    lua_settable(state, -4);
    lua_remove(state, -2);

    /* done */
}
示例#22
0
float bbStringToFloat( BBString *t ){
	char *p=bbStringToCString( t );
	float n=atof( p );
	bbMemFree( p );
	return n;
}
示例#23
0
文件: glue.cpp 项目: Chaduke/bah.mod
void bmx_roomquery_AddQuery_BINARY(RakNet::RoomQuery * query, BBString * columnName, const char * data, int inputLength, int op) {
	char * c = bbStringToCString(columnName);
	query->AddQuery_BINARY(c, data, inputLength, static_cast<DataStructures::Table::FilterQueryType>(op));
	bbMemFree(c);
}
示例#24
0
文件: glue.cpp 项目: Chaduke/bah.mod
int bmx_raknetroomsplugin_LogoffRoomsParticipant(RakNet::RoomsPlugin * rooms, BBString * userName, MaxSystemAddress * loginServerAddress) {
	char * u = bbStringToCString(userName);
	int ret = rooms->LogoffRoomsParticipant(u, loginServerAddress->Address());
	bbMemFree(u);
	return ret;
}
示例#25
0
/* table[key]  OR  table.key */
static int lugi_index_object(lua_State *state) {

#ifdef BMX_TABLE_SUPPORT > 1
    /* prior table behavior for BMax objects */
    lua_getfenv(state, 1);
    lua_pushvalue(state, 2);
    lua_gettable(state, -2);
    if ( lua_isnil(state, -1) == 0 ) {
        return 1;
    }

    lua_settop(state, 2);
#endif

    if (lua_type(state, 2) == LUA_TSTRING) {

        BBObject *obj = lua_tobmaxobject(state, 1);
        BBClass *clas = obj->clas;

        /* while class */
        do {

            /* get class VMT */
            lua_pushlightuserdata(state, clas);
            lua_gettable(state, LUA_REGISTRYINDEX);

            if ( lua_type(state, -1) == LUA_TTABLE ) /* there's a lookup table for the class.. */
            {

                lua_pushvalue(state, 2);
                lua_rawget(state, -2);

                int type = lua_type(state, -1);

                if (type == LUA_TUSERDATA) {		/* getting the value of a field */
                    fieldinfo_t *info = (fieldinfo_t*)lua_touserdata(state, -1);
                    bmx_field *field = (bmx_field*)((char*)obj+info->offset);

                    switch (info->type&(~BOOLFIELDOPT)) {
                    case BYTEFIELD:
                        if (info->type&BOOLFIELDOPT) {
                            lua_pushboolean(state, field->byte_value);
                        }
                        else {
                            lua_pushinteger(state, field->byte_value);
                        }
                        break;

                    case SHORTFIELD:
                        if (info->type&BOOLFIELDOPT) {
                            lua_pushboolean(state, field->short_value);
                        }
                        else {
                            lua_pushinteger(state, field->short_value);
                        }
                        break;

                    case INTFIELD:
                        if (info->type&BOOLFIELDOPT) {
                            lua_pushboolean(state, field->int_value);
                        }
                        else {
                            lua_pushinteger(state, field->int_value);
                        }
                        break;

                    case FLOATFIELD:
                        lua_pushnumber(state, field->float_value);
                        break;

                    case DOUBLEFIELD:
                        lua_pushnumber(state, field->double_value);
                        break;

                    case LONGFIELD:
                        if (info->type&BOOLFIELDOPT) {
                            lua_pushboolean(state, field->long_value);
                        }
                        else {
                            lua_pushinteger(state, field->long_value);
                        }
                        break;

                    case STRINGFIELD: {
                        char *strbuf = bbStringToCString(field->string_value);
                        lua_pushlstring(state, strbuf, field->string_value->length);
                        bbMemFree(strbuf);
                    }
                    break;

                    case ARRAYFIELD:
                        lua_pushbmaxarray(state, field->arr_value);
                        break;

                    case OBJECTFIELD:
                        lua_pushbmaxobject(state, field->obj_value);
                        break;

                    default:
                        return luaL_error(state, ERRORSTR("@lugi_index_object: Unrecognized field type (%d)."), info->type);
                        break;
                    }
                    return 1;

                    /** method **/
                }
                else if (type ==  LUA_TFUNCTION) {
                    return 1;
                }
                else {
                    lua_pop(state, 1);
                }
            } /* VMT found */

            /* pop previous VMT/nil */
            lua_pop(state, 1);

            /* iterate to the superclass */
            clas = clas->super;

        } while (clas != NULL);

    } /* key is string */

#if BMX_TABLE_SUPPORT < 1
    /* notify that there was an error accessing a field or method that does not exist */
    const char *objtype="invalid object";
    if (lua_isbmaxobject(state, 1))
        objtype = lua_tobmaxobject(state, 1)->clas->debug_scope->name;

    if ( (LUA_TNUMBER|LUA_TSTRING)&lua_type(state, 2) )
        return luaL_error(state, ERRORSTR("@lugi_index_object: Index (%s) for object<%s> is not a valid field or method."), lua_tostring(state, 2), objtype);
    else
        return luaL_error(state, ERRORSTR("@lugi_index_object: Index for object<%s> is not a valid field or method."), objtype);
#else
    lua_pushnil(state);
    return 1;
#endif
} /* lugi_index_object */
示例#26
0
文件: glue.cpp 项目: Chaduke/bah.mod
void bmx_chatfunc_SetChatMessage(RakNet::Chat_Func * func, BBString * message) {
	char * m = bbStringToCString(message);
	func->chatMessage = m;
	bbMemFree(m);
}
示例#27
0
double bbStringToDouble( BBString *t ){
	char *p=bbStringToCString( t );
	double n=atof( p );
	bbMemFree( p );
	return n;
}
void bbWriteStderr( BBString *t ){
	char *p=bbStringToCString( t );
	fprintf( stderr,"%s",p );
	fflush( stderr );
	bbMemFree(p);
}