本文整理汇总了C++中MOAILuaState::IsType方法的典型用法代码示例。如果您正苦于以下问题:C++ MOAILuaState::IsType方法的具体用法?C++ MOAILuaState::IsType怎么用?C++ MOAILuaState::IsType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MOAILuaState
的用法示例。
在下文中一共展示了MOAILuaState::IsType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AffirmMemberID
//----------------------------------------------------------------//
uintptr MOAISerializer::AffirmMemberID ( MOAILuaState& state, int idx ) {
// if we're an object, affirm as such...
if ( state.IsType ( idx, LUA_TUSERDATA )) {
return this->AffirmMemberID ( state.GetLuaObject < MOAILuaObject >( -1 ));
}
// bail if we're not a table
if ( !state.IsType ( idx, LUA_TTABLE )) return 0;
// get the table's address
uintptr memberID = ( uintptr )lua_topointer ( state, idx );
// bail if the table's already been added
if ( this->mTableMap.contains ( memberID )) return memberID;
// add the ref now to avoid cycles
this->mTableMap [ memberID ].SetStrongRef ( state, idx );
// follow the table's refs to make sure everything gets added
u32 itr = state.PushTableItr ( idx );
while ( state.TableItrNext ( itr )) {
this->AffirmMemberID ( state, -1 );
}
return memberID;
}
示例2: _gc
//----------------------------------------------------------------//
int MOAILuaObject::_gc ( lua_State* L ) {
MOAILuaState state ( L );
MOAILuaObject* self = ( MOAILuaObject* )state.GetPtrUserData ( 1 );
self->mCollected = true;
if ( MOAILuaRuntime::IsValid ()) {
if ( self->mFinalizer ) {
self->mFinalizer.PushRef ( state );
if ( state.IsType ( -1, LUA_TFUNCTION )) {
state.DebugCall ( 0, 0 );
}
else if ( state.IsType ( -1, LUA_TSTRING )) {
printf ( "%s\n", state.GetValue < cc8* >( -1, "" ));
}
else {
state.Pop ( 1 );
}
self->mFinalizer.Clear ();
}
if ( MOAILuaRuntime::Get ().mReportGC ) {
printf ( "GC %s <%p>\n", self->TypeName (), self );
}
}
if ( self->GetRefCount () == 0 ) {
delete ( self );
}
return 0;
}
示例3: _serializeToString
/** @name serializeToString
@text Serializes the specified table or object to a string.
@overload
@in table data The table to serialize.
@out string serialized The serialized string.
@overload
@in MOAILuaObject data The object to serialize.
@out string serialized The serialized string.
*/
int MOAISerializer::_serializeToString ( lua_State* L ) {
MOAILuaState state ( L );
if ( !( state.IsType ( 1, LUA_TTABLE ) || state.IsType ( 1, LUA_TUSERDATA ))) return 0;
MOAISerializer serializer;
serializer.AddLuaReturn ( state, 1 );
STLString result = serializer.SerializeToString ();
lua_pushstring ( state, result );
return 1;
}
示例4: _serializeToFile
/** @name serializeToFile
@text Serializes the specified table or object to a file.
@overload
@in string filename The file to create.
@in table data The table to serialize.
@out nil
@overload
@in string filename The file to create.
@in MOAILuaObject data The object to serialize.
@out nil
*/
int MOAISerializer::_serializeToFile ( lua_State* L ) {
MOAILuaState state ( L );
if ( !( state.IsType ( 1, LUA_TSTRING ))) return 0;
if ( !( state.IsType ( 2, LUA_TTABLE ) || state.IsType ( 2, LUA_TUSERDATA ))) return 0;
cc8* filename = state.GetValue < cc8* >( 1, "" );
MOAISerializer serializer;
serializer.AddLuaReturn ( state, 2 );
serializer.SerializeToFile ( filename );
return 0;
}
示例5: _tostring
//----------------------------------------------------------------//
int MOAILuaObject::_tostring ( lua_State* L ) {
MOAILuaState state ( L );
MOAILuaObject* data = ( MOAILuaObject* )state.GetPtrUserData ( 1 );
if ( data ) {
STLString str;
lua_getfield ( state, 1, "getClassName" );
if ( state.IsType ( -1, LUA_TFUNCTION )) {
lua_pushvalue ( state, 1 );
state.DebugCall ( 1, 1 );
cc8* classname = state.GetValue < cc8* >( -1, "" );
str.write ( "%p <%s>", data, classname );
state.Push ( str );
return 1;
}
str.write ( "%p <%s>", data, data->TypeName ());
state.Push ( str );
return 1;
}
return 0;
}
示例6: state
/** @name base64Encode
@text If a string is provided, encodes it in base64. Otherwise, encodes the current data stored in this object as a base64 encoded sequence of characters.
@opt MOAIDataBuffer self
@opt string data The string data to encode. You must either provide either a MOAIDataBuffer (via a :base64Encode type call) or string data (via a .base64Encode type call), but not both.
@out string output If passed a string, returns either a string or nil depending on whether it could be encoded. Otherwise the encoding occurs inline on the existing data buffer in this object, and nil is returned.
*/
int MOAIDataBuffer::_base64Encode ( lua_State* L ) {
MOAILuaState state ( L );
if ( state.IsType ( 1, LUA_TSTRING )) {
return state.Base64Encode ( 1 ) ? 1 : 0;
}
MOAIDataBuffer* self = state.GetLuaObject < MOAIDataBuffer >( 1, true );
if ( self ) {
if ( state.IsType ( 2, LUA_TSTRING )) {
size_t len;
cc8* str = lua_tolstring ( state, 2, &len );
self->Load (( void* )str, len );
}
self->Base64Encode ();
}
return 0;
}
示例7: _setValue
/** @name setValue
@text Sets an environment value and also triggers the listener
callback (if any).
@in string key
@opt variant value Default value is nil.
@out nil
*/
int MOAIEnvironment::_setValue ( lua_State* L ) {
MOAILuaState state ( L );
if ( state.IsType ( 1, LUA_TSTRING )) {
MOAIEnvironment& environment = MOAIEnvironment::Get ();
environment.SetValue ( state );
}
return 0;
}
示例8: _randSFMT
//----------------------------------------------------------------//
// TODO: doxygen
int MOAIMath::_randSFMT ( lua_State* L ) {
MOAILuaState state ( L );
double lower = 0.0;
double upper = 1.0;
if ( state.IsType ( 1, LUA_TNUMBER )) {
upper = state.GetValue < double >( 1, 0.0 );
if ( state.IsType ( 2, LUA_TNUMBER )) {
lower = upper;
upper = state.GetValue < double >( 2, 0.0 );
}
}
double r = sfmt_genrand_real1 ( MOAIMath::Get ().mSFMT ); // [0, 1]
state.Push ( lower + ( r * ( upper - lower )));
return 1;
}
示例9: IsMoaiUserdata
//----------------------------------------------------------------//
bool MOAILuaObject::IsMoaiUserdata ( MOAILuaState& state, int idx ) {
bool result = false;
if ( state.IsType ( idx, LUA_TUSERDATA )) {
if ( lua_getmetatable ( state, idx )) {
result = state.HasField ( -1, MOAI_TAG );
state.Pop ( 1 );
}
}
return result;
}
示例10: BindToLuaWithTable
//----------------------------------------------------------------//
void MOAILuaObject::BindToLuaWithTable ( MOAILuaState& state ) {
assert ( !this->mUserdata );
assert ( state.IsType ( -1, LUA_TTABLE ));
MOAILuaClass* type = this->GetLuaClass ();
assert ( type );
// create and initialize a new userdata
state.PushPtrUserData ( this );
// create and initialize the private table
lua_newtable ( state );
// set the ref to the private table
lua_pushvalue ( state, -3 );
lua_setfield ( state, -2, LUA_MEMBER_TABLE_NAME );
// initialize the private table
lua_pushcfunction ( state, MOAILuaObject::_gc );
lua_setfield ( state, -2, "__gc" );
lua_pushcfunction ( state, MOAILuaObject::_tostring );
lua_setfield ( state, -2, "__tostring" );
lua_pushcfunction ( state, MOAILuaObject::_index );
lua_setfield ( state, -2, "__index" );
lua_pushcfunction ( state, MOAILuaObject::_newindex );
lua_setfield ( state, -2, "__newindex" );
// make the interface table the instance table's meta
type->PushInterfaceTable ( state );
lua_setmetatable ( state, -2 );
// grab a ref to the instance table; attach it to the userdata
this->mInstanceTable = state.GetWeakRef ( -1 );
lua_setmetatable ( state, -2 );
// and take a ref back to the userdata
if ( this->GetRefCount () == 0 ) {
this->mUserdata.SetWeakRef ( state, -1 );
}
else {
this->mUserdata.SetStrongRef ( state, -1 );
}
// overwrite the member table
lua_replace ( state, -2 );
assert ( !lua_isnil ( state, -1 ));
}
示例11: _new
//----------------------------------------------------------------//
int MOAILuaClass::_new ( lua_State* L ) {
// upvalues:
// 1: interface table
// 2: original 'new'
MOAILuaState state ( L );
lua_pushvalue ( L, lua_upvalueindex ( 2 ));
if ( state.IsType ( -1, LUA_TFUNCTION )) {
// call the original new
state.DebugCall ( 0, 1 );
if ( state.IsType ( -1, LUA_TUSERDATA )) {
// get the ref table
if ( lua_getmetatable ( state, -1 )) {
// get the member table
if ( lua_getmetatable ( state, -1 )) {
// get the interface table
lua_pushvalue ( L, lua_upvalueindex ( 1 ));
// set the interface table as the metatable
lua_setmetatable ( L, -2 );
// done with the member table
lua_pop ( L, 1 );
}
// done with the ref table
lua_pop ( L, 1 );
}
}
return 1;
}
return 0;
}
示例12: _encode
/** @name encode
@text Encode a hierarchy of Lua tables into a JSON string.
@in table input
@out string result
*/
int MOAIJsonParser::_encode ( lua_State* L ) {
MOAILuaState state ( L );
if ( state.IsType ( 1, LUA_TTABLE )) {
json_t* json = _luaToJSON ( state, 1 );
if ( json ) {
int flags = state.IsType ( 2, 0 );
char* str = json_dumps ( json, flags );
json_decref ( json );
if ( str ) {
lua_pushstring ( state, str );
free ( str );
return 1;
}
}
}
return 0;
}
示例13: _inflate
/** @name inflate
@text Decompresses the string or the current data stored in this object using the DEFLATE algorithm.
@opt MOAIDataBuffer self
@opt string data The string data to inflate. You must either provide either a MOAIDataBuffer (via a :base64Decode type call) or string data (via a .base64Decode type call), but not both.
@in number windowBits The window bits used in the DEFLATE algorithm. Pass nil to use the default value.
@out string output If passed a string, returns either a string or nil depending on whether it could be decompressed. Otherwise the decompression occurs inline on the existing data buffer in this object, and nil is returned.
*/
int MOAIDataBuffer::_inflate ( lua_State* L ) {
MOAILuaState state ( L );
int windowBits = state.GetValue < int >( 2, USDeflateReader::DEFAULT_WBITS );
if ( state.IsType ( 1, LUA_TSTRING )) {
return state.Inflate ( 1, windowBits ) ? 1 : 0;
}
MOAIDataBuffer* self = state.GetLuaObject < MOAIDataBuffer >( 1, true );
if ( self ) {
self->Inflate ( windowBits );
}
return 0;
}
示例14: _showDialog
/** @name showDialog
@text Show a native dialog to the user.
@in string title The title of the dialog box. Can be nil.
@in string message The message to show the user. Can be nil.
@in string positive The text for the positive response dialog button. Can be nil.
@in string neutral The text for the neutral response dialog button. Can be nil.
@in string negative The text for the negative response dialog button. Can be nil.
@in bool cancelable Specifies whether or not the dialog is cancelable
@opt function callback A function to callback when the dialog is dismissed. Default is nil.
@out nil
*/
int MOAIDialogAndroid::_showDialog ( lua_State* L ) {
MOAILuaState state ( L );
cc8* title = lua_tostring ( state, 1 );
cc8* message = lua_tostring ( state, 2 );
cc8* positive = lua_tostring ( state, 3 );
cc8* neutral = lua_tostring ( state, 4 );
cc8* negative = lua_tostring ( state, 5 );
bool cancelable = lua_toboolean ( state, 6 );
if ( state.IsType ( 7, LUA_TFUNCTION )) {
// NOTE: This is fragile. We're storing the callback function in a global variable,
// effectively. Invoking the showDialog method multiple times in succession can
// therefore lead to unpredictable results. In fact, it's unknown how Android itself
// handles multiple invocations - are they queued? On iOS, UIAlertView is LIFO and
// new invocations supersede previous ones, but once dismissed, the system continues
// down the alert stack.
MOAIDialogAndroid::Get ().mDialogCallback.SetStrongRef ( state, 7 );
}
JNI_GET_ENV ( jvm, env );
JNI_GET_JSTRING ( title, jtitle );
JNI_GET_JSTRING ( message, jmessage );
JNI_GET_JSTRING ( positive, jpositive );
JNI_GET_JSTRING ( neutral, jneutral );
JNI_GET_JSTRING ( negative, jnegative );
jclass moai = env->FindClass ( "com/ziplinegames/moai/Moai" );
if ( moai == NULL ) {
ZLLog::Print ( "MOAIDialogAndroid: Unable to find java class %s", "com/ziplinegames/moai/Moai" );
} else {
jmethodID showDialog = env->GetStaticMethodID ( moai, "showDialog", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V" );
if ( showDialog == NULL ) {
ZLLog::Print ( "MOAIDialogAndroid: Unable to find static java method %s", "showDialog" );
} else {
env->CallStaticVoidMethod ( moai, showDialog, jtitle, jmessage, jpositive, jneutral, jnegative, cancelable );
}
}
return 0;
}
示例15: _deflate
/** @name deflate
@text Compresses the string or the current data stored in this object using the DEFLATE algorithm.
@opt MOAIDataBuffer self
@opt string data The string data to deflate. You must either provide either a MOAIDataBuffer (via a :base64Decode type call) or string data (via a .base64Decode type call), but not both.
@in number level The level used in the DEFLATE algorithm. Pass nil to use the default value.
@in number windowBits The window bits used in the DEFLATE algorithm. Pass nil to use the default value.
@out string output If passed a string, returns either a string or nil depending on whether it could be compressed. Otherwise the compression occurs inline on the existing data buffer in this object, and nil is returned.
*/
int MOAIDataBuffer::_deflate ( lua_State* L ) {
MOAILuaState state ( L );
int level = state.GetValue < int >( 2, USDeflateWriter::DEFAULT_LEVEL );
int windowBits = state.GetValue < int >( 3, USDeflateWriter::DEFAULT_WBITS );
if ( state.IsType ( 1, LUA_TSTRING )) {
return state.Deflate ( 1, level, windowBits ) ? 1 : 0;
}
MOAIDataBuffer* self = state.GetLuaObject < MOAIDataBuffer >( 1, true );
if ( self ) {
self->Deflate ( level, windowBits );
}
return 0;
}