您的位置:首页 > 编程语言 > Lua

在实现安卓和ios的sdk中 c++,java,lua 混编学习记录

2016-05-09 18:05 537 查看

调用的实现对于我这个记忆不要的人必须记录下来 以后有要使用还可以再复习和使用

因为文章就是一个流程 方便记忆 所以没有详细去描述(自己也才接触很多不懂呀)

GamePlatform.h 是父类 都继承此类
大部分函数可以不实现 在子类去完成函数的功能
C++调lua 调用lua 的 实现

#ifndef xxz_GamePlatform_h
#define xxz_GamePlatform_h
#include "cocos2d.h"
#include "CCLuaEngine.h"
NS_CC_BEGIN

//Android app跳转google play store
virtual void GooglePlayStore();

----------------------------
GamePlatform.cpp中部分实现的函数使用了 lua或者是coco2dx的API 在被继续或者时候是可以次函数可以被java 调用
void CGamePlatform::OnEventLoginOut()
{
CCLuaStack *pStack =  CCLuaEngine::defaultEngine()->getLuaStack();
if(pStack != NULL && m_nScripHandlerLogout != 0)
{
pStack->executeFunctionByHandler(m_nScripHandlerLogout, 0);
pStack->clean();
}
}

void CGamePlatform::AddOnEventFBDataHandler(int nHandler)
{
if (m_nScriptFBDataHandler)
{
CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nScriptFBDataHandler);
LUALOG("[LUA] Remove CCNode event handler: %d", m_nScriptFBDataHandler);
m_nScriptFBDataHandler = 0;
}
m_nScriptFBDataHandler = nHandler;
}


Android_Platform.h 例子

C++调java 在java实现函数

#ifndef Android_Platform_h
#define Android_Platform_h
#include "GamePlatform.h"
NS_CC_BEGIN
class CAndroid_Platform:public cocos2d::CGamePlatform
{
public:
CAndroid_Platform();
~CAndroid_Platform();
//Android app跳转google play store
//在这实现这个功能是方便 我自己熟悉java调用c++函数的过程 支付页面的不同 可以在父类实现空函数 然后在java中分别去实现自己需要的功能
virtual void GooglePlayStore();
};
NS_CC_END
#endif /* GP_Platform_h */
----------------------------------
//  CAndroid_Platform.cpp 以实现GooglePlayStore函数为例子  JNI实现 c++ 调用java
//Android app跳转google play store
void CAndroid_Platform::GooglePlayStore(){
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "PlatformSDK/PlatformSDK", "GooglePlayStore", "()V"))
{
t.env->CallStaticVoidMethod(t.classID, t.methodID);
t.env->DeleteLocalRef(t.classID);
}
}


Android_Platform_CallBack.h

java 调用c++ 函数在c++ 实现

#ifndef xxz_Android_Platform_CallBack
#define xxz_Android_Platform_CallBack
#include <stdio.h>
#include "GamePlatform.h"
class Android_Platform_CallBack
{
public:
static Android_Platform_CallBack* SharedInstance()
{
static Android_Platform_CallBack* pInstance = NULL;
if(pInstance == NULL)
{
pInstance = new Android_Platform_CallBack;
}
return pInstance;
}
void loginSucc(const char* account, const char* sid);
void logoutSucc();
protected:
Android_Platform_CallBack(){};
};
#endif

//   Android_Platform_CallBack.ccp
void Android_Platform_CallBack::inviteFaceBook(const char* strFB)
{
cocos2d::CGamePlatform::SharedInstance()->OnEventFBData(strFB);
}
--再java 中要实现的功能 下面两个方法附上链接是
[http://www.itnose.net/detail/6216605.html]

final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}

[http://blog.csdn.net/w00w12l/article/details/7674769](http://blog.csdn.net/w00w12l/article/details/7674769)
[java] view plain copy print?
private void method() {
// TODO Auto-generated method stub
Intent intent= new Intent();
intent.setAction("android.intent.action.VIEW");
Uri content_url = Uri.parse("http://www.baidu.com");
intent.setData(content_url);
startActivity(intent);
}


“PlatformSDK_PlatformSDK”

和 “Android_Platform_CallBack” 一起 在“PlatformSDK_PlatformSDK” 实现jin 配置调用c++

例子:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include "PlatformSDK_PlatformSDK.h"
#include "GamePlatform.h"
#include "Android_Platform_CallBack.h"
#include "platform/android/jni/JniHelper.h"
USING_NS_CC;
/*
* Class:     PlatformSDK_PlatformSDK
* Method:    refreshTokens
* Signature: (Ljava/lang/String)V
*/
JNIEXPORT void JNICALL Java_PlatformSDK_PlatformSDK_inviteFaceBook
(JNIEnv *Env, jclass thiz, jstring strFB)
{
const char* pStrFB = Env->GetStringUTFChars( strFB, NULL);
Android_Platform_CallBack::SharedInstance()->inviteFaceBook(pStrFB);
Env->ReleaseStringUTFChars(strFB, pStrFB);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java lua ios