Lua中调用C++方法
目前项目,使用了Lua脚本,至于使用Lua的好处不再赘述了。于是对Tolua做了一些小小的学习,总结一下吧。
主要说一下如何在Lua中调用C++方法。
Lua调用C++的桥梁,是tolua。tolua是什么,http://blog.csdn.net/killwd/article/details/1423923 这篇文章介绍的很详细。
我们需要手动做的,其实便是编写中间类,这个类被tolua直接使用,最终的目的是实现lua中对象方法和C++中对象方法的对应。
LuaCocos2d.cpp 完成了所有基本的cocos对象方法的转换,我们把它称之为一个桥梁。LuaCocos2d.cpp 是在CCLuaStack 中的init函数中调用的。
- tolua_Cocos2d_open(m_state);
1.CCLuaStack 中调用中间桥梁(比如LuaCocos2d)
2.桥梁里面(比如LuaCocos2d)实现各种方法的转换
这样,整个的重点就是桥梁的生成了。
看一下LuaCocos2d ,最重要的方法我认为是tolua_reg_types。
- /* function to register type */
- static void tolua_reg_types (lua_State* tolua_S)
- {
- tolua_usertype(tolua_S,"CCTransitionProgressOutIn");
- tolua_usertype(tolua_S,"CCControlSaturationBrightnessPicker");
- tolua_usertype(tolua_S,"CCShaky3D");
- tolua_usertype(tolua_S,"CCTransitionTurnOffTiles");
- tolua_usertype(tolua_S,"CCTransitionShrinkGrow");
- tolua_usertype(tolua_S,"CCFadeOutBLTiles");
- tolua_usertype(tolua_S,"CCProgressFromTo");
- tolua_usertype(tolua_S,"CCActionCamera");
- tolua_usertype(tolua_S,"CCFlipY3D");
- tolua_usertype(tolua_S,"CCLinkPosition");
- tolua_usertype(tolua_S,"CCEaseExponentialIn");
- tolua_usertype(tolua_S,"CCApplication");
- tolua_usertype(tolua_S,"CCControlHuePicker");
- tolua_usertype(tolua_S,"CCScaleTo");
- tolua_usertype(tolua_S,"CCTransitionFlipAngular");
- tolua_usertype(tolua_S,"CCEaseElasticOut");
- tolua_usertype(tolua_S,"CCAccelDeccelAmplitude");
- tolua_usertype(tolua_S,"CCDisplayData");
- tolua_usertype(tolua_S,"CCParticleRain");
- tolua_usertype(tolua_S,"CCTransitionSlideInB");
- tolua_usertype(tolua_S,"CCKeypadDispatcher");
- tolua_usertype(tolua_S,"CCDelayTime");
- tolua_usertype(tolua_S,"CCOrbitCamera");
- tolua_usertype(tolua_S,"CCLabelTTF");
- tolua_usertype(tolua_S,"CCScale9Sprite");
- tolua_usertype(tolua_S,"CCMoveTo");
- tolua_usertype(tolua_S,"CCTransitionSplitRows");
- tolua_usertype(tolua_S,"CCFollow");
- tolua_usertype(tolua_S,"CCMovementData");
- tolua_usertype(tolua_S,"CCBlink");
- tolua_usertype(tolua_S,"CCTexture2D");
- tolua_usertype(tolua_S,"CCTouch");
- tolua_usertype(tolua_S,"CCParticleSystemQuad");
- tolua_usertype(tolua_S,"CCTransitionMoveInB");
- tolua_usertype(tolua_S,"CCToggleVisibility");
- tolua_usertype(tolua_S,"cc_timeval");
- tolua_usertype(tolua_S,"CCTMXTilesetInfo");
- tolua_usertype(tolua_S,"CCParticleSun");
- tolua_usertype(tolua_S,"CCScene");
- tolua_usertype(tolua_S,"CCArmatureDataManager");
- tolua_usertype(tolua_S,"CCFadeIn");
- tolua_usertype(tolua_S,"CCTransitionFadeDown");
- tolua_usertype(tolua_S,"CCWavesTiles3D");
- tolua_usertype(tolua_S,"CCFadeOutDownTiles");
- tolua_usertype(tolua_S,"CCComponentContainer");
- tolua_usertype(tolua_S,"CCTMXTiledMap");
- tolua_usertype(tolua_S,"CCCardinalSplineBy");
- tolua_usertype(tolua_S,"CCTransitionZoomFlipAngular");
- tolua_usertype(tolua_S,"CCFlipY");
- tolua_usertype(tolua_S,"CCProgressTo");
- tolua_usertype(tolua_S,"CCReuseGrid");
- tolua_usertype(tolua_S,"CCShow");
- tolua_usertype(tolua_S,"CCEaseRateAction");
- tolua_usertype(tolua_S,"CCEaseBackIn");
- tolua_usertype(tolua_S,"CCTransitionScene");
- tolua_usertype(tolua_S,"CCGridAction");
- tolua_usertype(tolua_S,"CCFiniteTimeAction");
- tolua_usertype(tolua_S,"CCSpriteFrameCache");
- tolua_usertype(tolua_S,"CCMotionStreak");
- tolua_usertype(tolua_S,"CCAnimate");
- tolua_usertype(tolua_S,"CCTiledGrid3DAction");
- tolua_usertype(tolua_S,"CCPointArray");
- tolua_usertype(tolua_S,"CCTransitionProgressHorizontal");
- tolua_usertype(tolua_S,"CCRectShape");
- tolua_usertype(tolua_S,"ccColor3B");
- tolua_usertype(tolua_S,"CCTextureCache");
- tolua_usertype(tolua_S,"CCDevice");
- tolua_usertype(tolua_S,"CCFadeOutTRTiles");
- tolua_usertype(tolua_S,"CCMenuItemSprite");
- tolua_usertype(tolua_S,"CCEaseExponentialInOut");
- tolua_usertype(tolua_S,"CCFadeOutUpTiles");
- tolua_usertype(tolua_S,"CCWaves3D");
- tolua_usertype(tolua_S,"ccBlendFunc");
- tolua_usertype(tolua_S,"CCImage");
- tolua_usertype(tolua_S,"CCLens3D");
- tolua_usertype(tolua_S,"CCTintBy");
- tolua_usertype(tolua_S,"CCBool");
- tolua_usertype(tolua_S,"CCPoint");
- tolua_usertype(tolua_S,"CCParticleMeteor");
- tolua_usertype(tolua_S,"CCEaseElasticIn");
- tolua_usertype(tolua_S,"CCEaseSineIn");
- tolua_usertype(tolua_S,"CCCardinalSplineTo");
- tolua_usertype(tolua_S,"CCFloat");
- tolua_usertype(tolua_S,"CCWaves");
- tolua_usertype(tolua_S,"CCParticleFireworks");
- tolua_usertype(tolua_S,"CCEvent");
- tolua_usertype(tolua_S,"CCBaseData");
- tolua_usertype(tolua_S,"CCActionInterval");
- tolua_usertype(tolua_S,"CCRenderTexture");
- tolua_usertype(tolua_S,"CCObject");
- tolua_usertype(tolua_S,"CCEaseBackInOut");
- tolua_usertype(tolua_S,"CCAtlasNode");
- tolua_usertype(tolua_S,"CCEaseBackOut");
- tolua_usertype(tolua_S,"CCSize");
- tolua_usertype(tolua_S,"CCInteger");
- tolua_usertype(tolua_S,"CCParticleFlower");
- tolua_usertype(tolua_S,"CCLiquid");
- tolua_usertype(tolua_S,"CCEaseBounce");
- tolua_usertype(tolua_S,"CCSpeed");
- tolua_usertype(tolua_S,"CCFrameData");
- tolua_usertype(tolua_S,"CCTransitionMoveInL");
- tolua_usertype(tolua_S,"CCSpriteFrame");
- tolua_usertype(tolua_S,"CCJumpBy");
- tolua_usertype(tolua_S,"CCTransitionFadeTR");
- tolua_usertype(tolua_S,"CCControlUtils");
- tolua_usertype(tolua_S,"CCGridBase");
- tolua_usertype(tolua_S,"RGBA");
- tolua_usertype(tolua_S,"CCParticleDisplayData");
- tolua_usertype(tolua_S,"SimpleAudioEngine");
- tolua_usertype(tolua_S,"CCNotificationCenter");
- tolua_usertype(tolua_S,"CCPointShape");
- tolua_usertype(tolua_S,"CCSpriteBatchNode");
- tolua_usertype(tolua_S,"CCEaseSineInOut");
- tolua_usertype(tolua_S,"ccFontShadow");
- tolua_usertype(tolua_S,"CCTwirl");
- tolua_usertype(tolua_S,"CCCircleShape");
- tolua_usertype(tolua_S,"CCDrawNode");
- tolua_usertype(tolua_S,"CCControlColourPicker");
- tolua_usertype(tolua_S,"CCMenuItemLabel");
- tolua_usertype(tolua_S,"CCDouble");
- tolua_usertype(tolua_S,"CCTargetedAction");
- tolua_usertype(tolua_S,"CCGrid3DAction");
- tolua_usertype(tolua_S,"CCString");
- tolua_usertype(tolua_S,"CCRemoveSelf");
- tolua_usertype(tolua_S,"CCAnimationData");
- tolua_usertype(tolua_S,"CCTransitionMoveInR");
- tolua_usertype(tolua_S,"CCTransitionFade");
- tolua_usertype(tolua_S,"CCSkewBy");
- tolua_usertype(tolua_S,"CCFlipX");
- tolua_usertype(tolua_S,"CCActionManager");
- tolua_usertype(tolua_S,"CCTransitionSlideInT");
- tolua_usertype(tolua_S,"CCCatmullRomTo");
- tolua_usertype(tolua_S,"CCPolygonShape");
- tolua_usertype(tolua_S,"CCTransitionSceneOriented");
- tolua_usertype(tolua_S,"CCAnimationCache");
- tolua_usertype(tolua_S,"CCComponent");
- tolua_usertype(tolua_S,"CCTransitionSlideInR");
- tolua_usertype(tolua_S,"CCTransitionMoveInT");
- tolua_usertype(tolua_S,"CCLayerGradient");
- tolua_usertype(tolua_S,"CCShapeNode");
- tolua_usertype(tolua_S,"CCStopGrid");
- tolua_usertype(tolua_S,"CCTMXMapInfo");
- tolua_usertype(tolua_S,"CCConfiguration");
- tolua_usertype(tolua_S,"CCLayerColor");
- tolua_usertype(tolua_S,"CCMenuItemFont");
- tolua_usertype(tolua_S,"CCTransitionFadeUp");
- tolua_usertype(tolua_S,"CCTransitionProgressVertical");
- tolua_usertype(tolua_S,"CCAccelerometer");
- tolua_usertype(tolua_S,"CCProcessBase");
- tolua_usertype(tolua_S,"CCRect");
- tolua_usertype(tolua_S,"CCActionInstant");
- tolua_usertype(tolua_S,"CCTurnOffTiles");
- tolua_usertype(tolua_S,"CCParticleSnow");
- tolua_usertype(tolua_S,"CCMenuItemImage");
- tolua_usertype(tolua_S,"ccTexParams");
- tolua_usertype(tolua_S,"CCEaseSineOut");
- tolua_usertype(tolua_S,"CCCallFuncN");
- tolua_usertype(tolua_S,"CCTransitionPageTurn");
- tolua_usertype(tolua_S,"ccFontDefinition");
- tolua_usertype(tolua_S,"ccFontStroke");
- tolua_usertype(tolua_S,"CCTintTo");
- tolua_usertype(tolua_S,"CCTransitionCrossFade");
- tolua_usertype(tolua_S,"CCClippingRegionNode");
- tolua_usertype(tolua_S,"CCActionEase");
- tolua_usertype(tolua_S,"CCBone");
- tolua_usertype(tolua_S,"CCParallaxNode");
- tolua_usertype(tolua_S,"CCRotateTo");
- tolua_usertype(tolua_S,"CCArmature");
- tolua_usertype(tolua_S,"CCBatchNode");
- tolua_usertype(tolua_S,"CCMovementBoneData");
- tolua_usertype(tolua_S,"CCShakyTiles3D");
- tolua_usertype(tolua_S,"CCArmatureDisplayData");
- tolua_usertype(tolua_S,"CCNode");
- tolua_usertype(tolua_S,"CCArmatureData");
- tolua_usertype(tolua_S,"CCArmatureAnimation");
- tolua_usertype(tolua_S,"CCSpriteDisplayData");
- tolua_usertype(tolua_S,"CCBezierTo");
- tolua_usertype(tolua_S,"CCDeccelAmplitude");
- tolua_usertype(tolua_S,"CCTweenType");
- tolua_usertype(tolua_S,"CCBoneData");
- tolua_usertype(tolua_S,"CCTableView");
- tolua_usertype(tolua_S,"CCTableViewCell");
- tolua_usertype(tolua_S,"CCTransitionProgress");
- tolua_usertype(tolua_S,"CCEditBox");
- tolua_usertype(tolua_S,"HSV");
- tolua_usertype(tolua_S,"CCRotateBy");
- tolua_usertype(tolua_S,"CCControlStepper");
- tolua_usertype(tolua_S,"CCControlSlider");
- tolua_usertype(tolua_S,"CCMoveBy");
- tolua_usertype(tolua_S,"CCParticleGalaxy");
- tolua_usertype(tolua_S,"CCCamera");
- tolua_usertype(tolua_S,"CCSequence");
- tolua_usertype(tolua_S,"CCTileMapAtlas");
- tolua_usertype(tolua_S,"tCCParticle");
- tolua_usertype(tolua_S,"CCCatmullRomBy");
- tolua_usertype(tolua_S,"CCHide");
- tolua_usertype(tolua_S,"CCControlButton");
- tolua_usertype(tolua_S,"CCJumpTiles3D");
- tolua_usertype(tolua_S,"CCTransitionJumpZoom");
- tolua_usertype(tolua_S,"CCTMXLayer");
- tolua_usertype(tolua_S,"CCControl");
- tolua_usertype(tolua_S,"AssetsManager");
- tolua_usertype(tolua_S,"CCScheduler");
- tolua_usertype(tolua_S,"CCDirector");
- tolua_usertype(tolua_S,"CCMenuItemToggle");
- tolua_usertype(tolua_S,"CCEGLView");
- tolua_usertype(tolua_S,"ccBezierConfig");
- tolua_usertype(tolua_S,"CCFadeTo");
- tolua_usertype(tolua_S,"CCTouchDispatcher");
- tolua_usertype(tolua_S,"CCMenuItemAtlasFont");
- tolua_usertype(tolua_S,"SEL_MenuHandler");
- tolua_usertype(tolua_S,"CCEventDispatcher");
- tolua_usertype(tolua_S,"CCParticleSystem");
- tolua_usertype(tolua_S,"CCJumpTo");
- tolua_usertype(tolua_S,"CCMenu");
- tolua_usertype(tolua_S,"ccColor4F");
- tolua_usertype(tolua_S,"CCEaseExponentialOut");
- tolua_usertype(tolua_S,"CCSet");
- tolua_usertype(tolua_S,"CCCallFunc");
- tolua_usertype(tolua_S,"CCLabelAtlas");
- tolua_usertype(tolua_S,"CCLabelBMFont");
- tolua_usertype(tolua_S,"CCEaseBounceIn");
- tolua_usertype(tolua_S,"CCPlace");
- tolua_usertype(tolua_S,"CCSprite");
- tolua_usertype(tolua_S,"CCFileUtils");
- tolua_usertype(tolua_S,"CCLayer");
- tolua_usertype(tolua_S,"CCTransitionSplitCols");
- tolua_usertype(tolua_S,"CCPageTurn3D");
- tolua_usertype(tolua_S,"CCEaseIn");
- tolua_usertype(tolua_S,"CCTransitionProgressRadialCW");
- tolua_usertype(tolua_S,"CCEaseElastic");
- tolua_usertype(tolua_S,"CCTransitionProgressRadialCCW");
- tolua_usertype(tolua_S,"CCEaseOut");
- tolua_usertype(tolua_S,"CCBezierBy");
- tolua_usertype(tolua_S,"CCScrollView");
- tolua_usertype(tolua_S,"CCUserDefault");
- tolua_usertype(tolua_S,"CCProgressTimer");
- tolua_usertype(tolua_S,"CCDictionary");
- tolua_usertype(tolua_S,"CCParticleFire");
- tolua_usertype(tolua_S,"CCTransitionFlipY");
- tolua_usertype(tolua_S,"CCTMXLayerInfo");
- tolua_usertype(tolua_S,"CCTransitionFadeBL");
- tolua_usertype(tolua_S,"CCShuffleTiles");
- tolua_usertype(tolua_S,"CCTransitionSlideInL");
- tolua_usertype(tolua_S,"CCRipple3D");
- tolua_usertype(tolua_S,"CCRepeat");
- tolua_usertype(tolua_S,"CCClippingNode");
- tolua_usertype(tolua_S,"CCTransitionProgressInOut");
- tolua_usertype(tolua_S,"CCParticleSpiral");
- tolua_usertype(tolua_S,"CCTransitionZoomFlipY");
- tolua_usertype(tolua_S,"CCEaseBounceInOut");
- tolua_usertype(tolua_S,"CCTransitionZoomFlipX");
- tolua_usertype(tolua_S,"CCTransitionFlipX");
- tolua_usertype(tolua_S,"CCSpawn");
- tolua_usertype(tolua_S,"CCTransitionRotoZoom");
- tolua_usertype(tolua_S,"CCEaseInOut");
- tolua_usertype(tolua_S,"CCShatteredTiles3D");
- tolua_usertype(tolua_S,"CCAccelAmplitude");
- tolua_usertype(tolua_S,"CCParticleSmoke");
- tolua_usertype(tolua_S,"CCTMXObjectGroup");
- tolua_usertype(tolua_S,"CCFadeOut");
- tolua_usertype(tolua_S,"CCLayerMultiplex");
- tolua_usertype(tolua_S,"CCControlPotentiometer");
- tolua_usertype(tolua_S,"CCParticleExplosion");
- tolua_usertype(tolua_S,"CCGLProgram");
- tolua_usertype(tolua_S,"CCMenuItem");
- tolua_usertype(tolua_S,"ccColor4B");
- tolua_usertype(tolua_S,"CCFlipX3D");
- tolua_usertype(tolua_S,"CCSplitRows");
- tolua_usertype(tolua_S,"CCArray");
- tolua_usertype(tolua_S,"CCReverseTime");
- tolua_usertype(tolua_S,"CCSkewTo");
- tolua_usertype(tolua_S,"CCParticleBatchNode");
- tolua_usertype(tolua_S,"CCGraySprite");
- tolua_usertype(tolua_S,"CCAnimation");
- tolua_usertype(tolua_S,"CCRepeatForever");
- tolua_usertype(tolua_S,"CCTime");
- tolua_usertype(tolua_S,"CCAction");
- tolua_usertype(tolua_S,"CCTextFieldTTF");
- tolua_usertype(tolua_S,"CCTextureAtlas");
- tolua_usertype(tolua_S,"CCScaleBy");
- tolua_usertype(tolua_S,"CCEaseElasticInOut");
- tolua_usertype(tolua_S,"CCSplitCols");
- tolua_usertype(tolua_S,"CCEaseBounceOut");
- tolua_usertype(tolua_S,"CCAnimationFrame");
- tolua_usertype(tolua_S,"CCControlSwitch");
- }
拿CCLabelTTF举例,你在里面搜便可以明白了。第一个参数先不用管,第二个是CCLabelTTF在调用的方法名,第三个参数便是这个文件中定义的方法,你找到一看便会明白了。
- #ifdef __cplusplus
- tolua_cclass(tolua_S,"CCLabelTTF","CCLabelTTF","CCSprite",tolua_collect_CCLabelTTF);
- #else
- tolua_cclass(tolua_S,"CCLabelTTF","CCLabelTTF","CCSprite",NULL);
- #endif
- tolua_beginmodule(tolua_S,"CCLabelTTF");
- tolua_function(tolua_S,"new",tolua_Cocos2d_CCLabelTTF_new00);
- tolua_function(tolua_S,"new_local",tolua_Cocos2d_CCLabelTTF_new00_local);
- tolua_function(tolua_S,".call",tolua_Cocos2d_CCLabelTTF_new00_local);
- tolua_function(tolua_S,"delete",tolua_Cocos2d_CCLabelTTF_delete00);
- tolua_function(tolua_S,"create",tolua_Cocos2d_CCLabelTTF_create00);
- tolua_function(tolua_S,"create",tolua_Cocos2d_CCLabelTTF_create01);
- tolua_function(tolua_S,"create",tolua_Cocos2d_CCLabelTTF_create02);
- tolua_function(tolua_S,"create",tolua_Cocos2d_CCLabelTTF_create03);
- tolua_function(tolua_S,"initWithString",tolua_Cocos2d_CCLabelTTF_initWithString00);
- tolua_function(tolua_S,"initWithString",tolua_Cocos2d_CCLabelTTF_initWithString01);
- tolua_function(tolua_S,"initWithString",tolua_Cocos2d_CCLabelTTF_initWithString02);
- tolua_function(tolua_S,"initWithStringAndTextDefinition",tolua_Cocos2d_CCLabelTTF_initWithStringAndTextDefinition00);
- tolua_function(tolua_S,"init",tolua_Cocos2d_CCLabelTTF_init00);
- tolua_function(tolua_S,"setTextDefinition",tolua_Cocos2d_CCLabelTTF_setTextDefinition00);
- tolua_function(tolua_S,"getTextDefinition",tolua_Cocos2d_CCLabelTTF_getTextDefinition00);
- tolua_function(tolua_S,"enableShadow",tolua_Cocos2d_CCLabelTTF_enableShadow00);
- tolua_function(tolua_S,"disableShadow",tolua_Cocos2d_CCLabelTTF_disableShadow00);
- tolua_function(tolua_S,"enableStroke",tolua_Cocos2d_CCLabelTTF_enableStroke00);
- tolua_function(tolua_S,"disableStroke",tolua_Cocos2d_CCLabelTTF_disableStroke00);
- tolua_function(tolua_S,"setFontFillColor",tolua_Cocos2d_CCLabelTTF_setFontFillColor00);
- tolua_function(tolua_S,"setString",tolua_Cocos2d_CCLabelTTF_setString00);
- tolua_function(tolua_S,"getString",tolua_Cocos2d_CCLabelTTF_getString00);
- tolua_function(tolua_S,"getHorizontalAlignment",tolua_Cocos2d_CCLabelTTF_getHorizontalAlignment00);
- tolua_function(tolua_S,"setHorizontalAlignment",tolua_Cocos2d_CCLabelTTF_setHorizontalAlignment00);
- tolua_function(tolua_S,"getVerticalAlignment",tolua_Cocos2d_CCLabelTTF_getVerticalAlignment00);
- tolua_function(tolua_S,"setVerticalAlignment",tolua_Cocos2d_CCLabelTTF_setVerticalAlignment00);
- tolua_function(tolua_S,"getDimensions",tolua_Cocos2d_CCLabelTTF_getDimensions00);
- tolua_function(tolua_S,"setDimensions",tolua_Cocos2d_CCLabelTTF_setDimensions00);
- tolua_function(tolua_S,"getFontSize",tolua_Cocos2d_CCLabelTTF_getFontSize00);
- tolua_function(tolua_S,"setFontSize",tolua_Cocos2d_CCLabelTTF_setFontSize00);
- tolua_function(tolua_S,"getFontName",tolua_Cocos2d_CCLabelTTF_getFontName00);
- tolua_function(tolua_S,"setFontName",tolua_Cocos2d_CCLabelTTF_setFontName00);
- tolua_endmodule(tolua_S);
假如我们有自己的C++方法需要在Lua中调用,也按照这两个大步骤完成即可。中间桥梁类参考LuaCocos2d.cpp即可。
Lua中调用C++方法的更多相关文章
- Lua中“.”调用方法与“:”调用方法的区别
Lua中“.”调用方法与“:”调用方法的区别: ...
- 【问题】Asp.net MVC 的cshtml页面中调用JS方法传递字符串变量参数
[问题]Asp.net MVC 的cshtml页面中调用JS方法传递字符串变量参数. [解决]直接对变量加引号,如: <button onclick="deleteProduct('@ ...
- C# 构造函数中调用虚方法的问题
请看下面代码: using System; public class A{ public A(){ M1(); } public virtual void M1(){} } public class ...
- 【09】绝不在构造和析构过程中调用virtual方法
1.绝不在构造和析构过程中调用virtual方法,为啥? 原因很简单,对于前者,这种情况下,子类专有成分还没有构造,对于后者,子类专有成分已经销毁,因此调用的并不是子类重写的方法,这不是程序员所期望的 ...
- angularjs 动态表单, 原生事件中调用angular方法
1. 原生事件中调用angular方法, 比如 input的onChange事件想调用angular里面定义的方法 - onChange="angular.element(this).sco ...
- 避免在构造函数中调用虚方法(Do not call overridable methods in constructors)
CLR中说道,不要在构造函数中调用虚方法,原因是假如被实例化的类型重写了虚方法,就会执行派生类型对虚方法的实现.但在这个时候,尚未完成对继承层次结构中所有字段的初始化.所以,调用虚方法会导致不可预测的 ...
- Python 在子类中调用父类方法详解(单继承、多层继承、多重继承)
Python 在子类中调用父类方法详解(单继承.多层继承.多重继承) by:授客 QQ:1033553122 测试环境: win7 64位 Python版本:Python 3.3.5 代码实践 ...
- JS与OC交互,JS中调用OC方法(获取JSContext的方式)
最近用到JS和OC原生方法调用的问题,查了许多资料都语焉不详,自己记录一下吧,如果有误欢迎联系我指出. JS中调用OC方法有三种方式: 1.通过获取JSContext的方式直接调用OC方法 2.通过继 ...
- python基础----继承与派生、组合、接口与归一化设计、抽象类、子类中调用父类方法
一.什么是继承 继承是一种创建新的类的方式,在pyth ...
随机推荐
- javabean的内省技术和BeanUtils的使用
一.关于javabean javabean是固定写法的java类 书写格式为: 1)必须有无参构造函数 2)属性必须私有, 我们称为字段 3)提供标准的getter和setter 例: name 字段 ...
- ajax的一些实用技巧
1.尽量优先采用ajax获取html文件,然后再操作dom把数据填充到里面 在实际项目中,如果前端开发人员没有把页面给切分开,那么有如下两种办法可供选择:其一是,在各种点击事件中,用js去拼接并在拼接 ...
- iOS开发多线程编程2 - NSOperation
1.简介 NSOperation实例封装了需要执行的操作和执行操作所需的数据,并且能够以并发或非并发的方式执行这个操作. NSOperation本身是抽象基类,因此必须使用它的子类,使用NSOpera ...
- git初始化之git config
git初始化之git config 1. 下面的命令将修改/home/[username]/.gitconfig文件,也就是说下面的配置只对每一个ssh的用户可见,所以每个人都需要做. 提 ...
- Delphi DBGrid双击事件、单元格操作
1.得到当前格子中的内容:DBGrid1.Fields[DBGrid1.SelectedIndex].DisplayText;把DBGrid1.SelectedIndex改为你所希望引用的字段就可以了 ...
- 【EF】Entity Framework Core 2.0 特性介绍和使用指南
阅读目录 前言 获取和使用 新特性 项目升级和核心API变化 下一步计划 遗憾的地方 回到目录 前言 这是.Net Core 2.0生态生态介绍的最后一篇,EF一直是我喜欢的一个ORM框架,随着版本升 ...
- 【bzoj5049】[Lydsy九月月赛]导航系统 并查集+双向BFS最短路
题目描述 给你一张 $n$ 个点 $m$ 条边的随机图,边权为1.$k$ 次询问两点间最短路,不连通则输出-1. 输入 第一行包含3个正整数n,m,k(2<=n<=100000,1< ...
- 【hdu3555】Bomb 数位dp
题目描述 求 1~N 内包含数位串 “49” 的数的个数. 输入 The first line of input consists of an integer T (1 <= T <= 1 ...
- poj 1422 Air Raid (二分匹配)
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6520 Accepted: 3877 Descript ...
- hadoop 将HDFS上多个小文件合并到SequenceFile里
背景:hdfs上的文件最好和hdfs的块大小的N倍.如果文件太小,浪费namnode的元数据存储空间以及内存,如果文件分块不合理也会影响mapreduce中map的效率. 本例中将小文件的文件名作为k ...