mirror of https://github.com/axmolengine/axmol.git
issue #528: refactor lua ok on Android
This commit is contained in:
parent
022e2b9998
commit
2f97a43439
|
@ -94,20 +94,19 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
if (pFileContent)
|
||||
{
|
||||
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
|
||||
char *pTmp = new char[size + 1];
|
||||
pTmp[size] = '\0';
|
||||
memcpy(pTmp, pFileContent, size);
|
||||
char *pCodes = new char[size + 1];
|
||||
pCodes[size] = '\0';
|
||||
memcpy(pCodes, pFileContent, size);
|
||||
delete[] pFileContent;
|
||||
|
||||
string code(pTmp);
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeString(code);
|
||||
delete []pTmp;
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeString(pCodes);
|
||||
delete []pCodes;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
// CCLuaScriptModule::sharedLuaScriptModule()->executeScriptFile("./../../HelloLua/Resource/hello.lua");
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteScriptFile("./../../HelloLua/Resource/hello.lua");
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeScriptFile("./../../HelloLua/Resource/hello.lua");
|
||||
|
||||
/*
|
||||
* Another way to run lua script.
|
||||
|
|
|
@ -24,10 +24,6 @@ do
|
|||
fi
|
||||
done
|
||||
|
||||
# to enable lua
|
||||
ENABLE_LUA=true
|
||||
export ENABLE_LUA
|
||||
|
||||
# build
|
||||
$ANDROID_NDK_ROOT/ndk-build -C $GAME_ANDROID_ROOT $*
|
||||
|
||||
|
|
|
@ -3,7 +3,10 @@ include $(CLEAR_VARS)
|
|||
LOCAL_MODULE := game
|
||||
|
||||
LOCAL_SRC_FILES := main.cpp \
|
||||
../../../Classes/AppDelegate.cpp
|
||||
../../../Classes/AppDelegate.cpp \
|
||||
../../../../lua/cocos2dx_support/LuaEngineImpl.cpp \
|
||||
../../../../lua/cocos2dx_support/LuaCocos2d.cpp \
|
||||
../../../../lua/cocos2dx_support/LuaEngine.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../cocos2dx \
|
||||
$(LOCAL_PATH)/../../../../cocos2dx/platform \
|
||||
|
@ -12,7 +15,8 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../cocos2dx \
|
|||
$(LOCAL_PATH)/../../../../CocosDenshion/include \
|
||||
$(LOCAL_PATH)/../../../Classes \
|
||||
$(LOCAL_PATH)/../../../../lua/src \
|
||||
$(LOCAL_PATH)/../../../../lua/tolua
|
||||
$(LOCAL_PATH)/../../../../lua/tolua \
|
||||
$(LOCAL_PATH)/../../../../lua/cocos2dx_support
|
||||
|
||||
# it is used for ndk-r4
|
||||
# if you build with nkd-r4, uncomment it
|
||||
|
@ -36,6 +40,4 @@ LOCAL_LDLIBS := -llog -lGLESv1_CM -llog -lz \
|
|||
|
||||
LOCAL_STATIC_LIBRARIES := libcocos2d libcocosdenshion liblua
|
||||
|
||||
LOCAL_CFLAGS := -DENABLE_LUA
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
|
@ -66,6 +66,7 @@ platform/android/CCEGLView_android.cpp \
|
|||
platform/android/CCAccelerometer_android.cpp \
|
||||
platform/android/CCApplication_android.cpp \
|
||||
platform/android/Cocos2dJni.cpp \
|
||||
script_support/CCScriptSupport.cpp \
|
||||
sprite_nodes/CCAnimation.cpp \
|
||||
sprite_nodes/CCAnimationCache.cpp \
|
||||
sprite_nodes/CCSprite.cpp \
|
||||
|
@ -96,17 +97,8 @@ tileMap_parallax_nodes/CCTMXTiledMap.cpp \
|
|||
tileMap_parallax_nodes/CCTMXXMLParser.cpp \
|
||||
tileMap_parallax_nodes/CCTileMapAtlas.cpp \
|
||||
touch_dispatcher/CCTouchDispatcher.cpp \
|
||||
touch_dispatcher/CCTouchHandler.cpp
|
||||
touch_dispatcher/CCTouchHandler.cpp \
|
||||
|
||||
ifeq ($(ENABLE_LUA), true)
|
||||
LOCAL_SRC_FILES += lua_support/CCLuaSrcipt.cpp \
|
||||
lua_support/LuaCocos2d.cpp
|
||||
|
||||
LOCAL_CFLAGS := -DENABLE_LUA -DUSE_FILE32API
|
||||
else
|
||||
# define the macro to compile through support/zip_support/ioapi.c
|
||||
LOCAL_CFLAGS := -DUSE_FILE32API
|
||||
endif
|
||||
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ \
|
||||
|
@ -127,9 +119,9 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/ \
|
|||
$(LOCAL_PATH)/platform/third_party/android/skia/text \
|
||||
$(LOCAL_PATH)/platform/third_party/android/skia/utils \
|
||||
$(LOCAL_PATH)/platform/third_party/android/skia/views \
|
||||
$(LOCAL_PATH)/platform/third_party/android/skia/xml \
|
||||
$(LOCAL_PATH)/../lua/src \
|
||||
$(LOCAL_PATH)/../lua/tolua
|
||||
$(LOCAL_PATH)/platform/third_party/android/skia/xml
|
||||
|
||||
|
||||
LOCAL_CFLAGS := -DUSE_FILE32API
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
|
|
@ -165,7 +165,7 @@ void CCTimer::update(ccTime dt)
|
|||
else if (m_scriptFunc.size())
|
||||
{
|
||||
// call script function
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteFuction(m_scriptFunc.c_str());
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeFuction(m_scriptFunc.c_str());
|
||||
m_fElapsed = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -334,7 +334,7 @@ namespace cocos2d {
|
|||
(m_pSelectorTarget->*m_pCallFunc)();
|
||||
}
|
||||
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteCallFunc(m_scriptFuncName.c_str());
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFunc(m_scriptFuncName.c_str());
|
||||
}
|
||||
//
|
||||
// CallFuncN
|
||||
|
@ -346,7 +346,7 @@ namespace cocos2d {
|
|||
(m_pSelectorTarget->*m_pCallFuncN)(m_pTarget);
|
||||
}
|
||||
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteCallFuncN(m_scriptFuncName.c_str(),
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFuncN(m_scriptFuncName.c_str(),
|
||||
m_pTarget);
|
||||
}
|
||||
CCCallFuncN * CCCallFuncN::actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncN selector)
|
||||
|
@ -462,7 +462,7 @@ namespace cocos2d {
|
|||
(m_pSelectorTarget->*m_pCallFuncND)(m_pTarget, m_pData);
|
||||
}
|
||||
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteCallFuncND(m_scriptFuncName.c_str(),
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFuncND(m_scriptFuncName.c_str(),
|
||||
m_pTarget,
|
||||
m_pData);
|
||||
}
|
||||
|
@ -487,7 +487,7 @@ namespace cocos2d {
|
|||
(m_pSelectorTarget->*m_pCallFuncO)(m_pObject);
|
||||
}
|
||||
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteCallFunc0(m_scriptFuncName.c_str(),
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFunc0(m_scriptFuncName.c_str(),
|
||||
m_pObject);
|
||||
}
|
||||
CCCallFuncO * CCCallFuncO::actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncO selector, CCObject* pObject)
|
||||
|
|
|
@ -26,6 +26,7 @@ THE SOFTWARE.
|
|||
#ifndef __CCINSTANT_ACTION_H__
|
||||
#define __CCINSTANT_ACTION_H__
|
||||
|
||||
#include <string>
|
||||
#include "CCAction.h"
|
||||
#include "selector_protocol.h"
|
||||
|
||||
|
|
|
@ -21,21 +21,21 @@ class CC_DLL CCScriptEngineProtocol
|
|||
{
|
||||
public:
|
||||
// functions for excute touch event
|
||||
virtual bool excuteTouchEvent(const char *pszFuncName, CCTouch *pTouch) = 0;
|
||||
virtual bool excuteTouchesEvent(const char *pszFuncName, CCSet *pTouches) = 0;
|
||||
virtual bool executeTouchEvent(const char *pszFuncName, CCTouch *pTouch) = 0;
|
||||
virtual bool executeTouchesEvent(const char *pszFuncName, CCSet *pTouches) = 0;
|
||||
|
||||
// functions for CCCallFuncX
|
||||
virtual bool excuteCallFunc(const char *pszFuncName) = 0;
|
||||
virtual bool excuteCallFuncN(const char *pszFuncName, CCNode *pNode) = 0;
|
||||
virtual bool excuteCallFuncND(const char *pszFuncName, CCNode *pNode, void *pData) = 0;
|
||||
virtual bool excuteCallFunc0(const char *pszFuncName, CCObject *pObject) = 0;
|
||||
virtual bool executeCallFunc(const char *pszFuncName) = 0;
|
||||
virtual bool executeCallFuncN(const char *pszFuncName, CCNode *pNode) = 0;
|
||||
virtual bool executeCallFuncND(const char *pszFuncName, CCNode *pNode, void *pData) = 0;
|
||||
virtual bool executeCallFunc0(const char *pszFuncName, CCObject *pObject) = 0;
|
||||
|
||||
// excute a script function without params
|
||||
virtual bool excuteFuction(const char *pszFuncName) = 0;
|
||||
virtual bool executeFuction(const char *pszFuncName) = 0;
|
||||
// excute a script file
|
||||
virtual bool excuteScriptFile(const char* pszFileName) = 0;
|
||||
virtual bool executeScriptFile(const char* pszFileName) = 0;
|
||||
// excute script from string
|
||||
virtual bool excuteString(const char* pszCodes) = 0;
|
||||
virtual bool executeString(const char* pszCodes) = 0;
|
||||
};
|
||||
|
||||
class CC_DLL CCScriptEngineManager
|
||||
|
|
|
@ -106,7 +106,7 @@ public:
|
|||
{
|
||||
if (m_pEventTypeFuncMap)
|
||||
{
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteTouchEvent((*m_pEventTypeFuncMap)[eventType].c_str(),
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeTouchEvent((*m_pEventTypeFuncMap)[eventType].c_str(),
|
||||
pTouch);
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ public:
|
|||
{
|
||||
if (m_pEventTypeFuncMap)
|
||||
{
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteTouchesEvent((*m_pEventTypeFuncMap)[eventType].c_str(),
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeTouchesEvent((*m_pEventTypeFuncMap)[eventType].c_str(),
|
||||
pTouches);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ namespace cocos2d{
|
|||
|
||||
if (m_functionName.size())
|
||||
{
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->excuteCallFunc(m_functionName.c_str());
|
||||
CCScriptEngineManager::sharedScriptEngineManager()->getScriptEngine()->executeCallFunc(m_functionName.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
b117ae900d20124687f8c9e8bf92c3bcc174eeaa
|
||||
254504a5833f5d377c88879c322fa847aea1d9d8
|
|
@ -1,55 +1,55 @@
|
|||
#include "LuaEngine.h"
|
||||
#include "CCLuaSrcipt.h"
|
||||
#include "LuaEngineImpl.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
// functions for excute touch event
|
||||
bool LuaEngine::excuteTouchEvent(const char *pszFuncName, CCTouch *pTouch)
|
||||
bool LuaEngine::executeTouchEvent(const char *pszFuncName, CCTouch *pTouch)
|
||||
{
|
||||
return CCLuaScriptModule::sharedLuaScriptModule()->executeTouch(pszFuncName, pTouch);
|
||||
}
|
||||
|
||||
bool LuaEngine::excuteTouchesEvent(const char *pszFuncName, CCSet *pTouches)
|
||||
bool LuaEngine::executeTouchesEvent(const char *pszFuncName, CCSet *pTouches)
|
||||
{
|
||||
return CCLuaScriptModule::sharedLuaScriptModule()->executeTouchesEvent(pszFuncName, pTouches);
|
||||
}
|
||||
|
||||
// functions for CCCallFuncX
|
||||
bool LuaEngine::excuteCallFunc(const char *pszFuncName)
|
||||
bool LuaEngine::executeCallFunc(const char *pszFuncName)
|
||||
{
|
||||
return CCLuaScriptModule::sharedLuaScriptModule()->executeCallFunc(pszFuncName);
|
||||
}
|
||||
|
||||
bool LuaEngine::excuteCallFuncN(const char *pszFuncName, CCNode *pNode)
|
||||
bool LuaEngine::executeCallFuncN(const char *pszFuncName, CCNode *pNode)
|
||||
{
|
||||
return CCLuaScriptModule::sharedLuaScriptModule()->executeCallFuncN(pszFuncName, pNode);
|
||||
}
|
||||
|
||||
bool LuaEngine::excuteCallFuncND(const char *pszFuncName, CCNode *pNode, void *pData)
|
||||
bool LuaEngine::executeCallFuncND(const char *pszFuncName, CCNode *pNode, void *pData)
|
||||
{
|
||||
return CCLuaScriptModule::sharedLuaScriptModule()->executeCallFuncND(pszFuncName, pNode, pData);
|
||||
}
|
||||
|
||||
bool LuaEngine::excuteCallFunc0(const char *pszFuncName, CCObject *pObject)
|
||||
bool LuaEngine::executeCallFunc0(const char *pszFuncName, CCObject *pObject)
|
||||
{
|
||||
// use executeCallFuncN() to implement it
|
||||
return CCLuaScriptModule::sharedLuaScriptModule()->executeCallFuncO(pszFuncName, pObject);
|
||||
}
|
||||
|
||||
// excute a script function without params
|
||||
bool LuaEngine::excuteFuction(const char *pszFuncName)
|
||||
bool LuaEngine::executeFuction(const char *pszFuncName)
|
||||
{
|
||||
return CCLuaScriptModule::sharedLuaScriptModule()->executeScriptGlobal(pszFuncName);
|
||||
}
|
||||
|
||||
// excute a script file
|
||||
bool LuaEngine::excuteScriptFile(const char* pszFileName)
|
||||
bool LuaEngine::executeScriptFile(const char* pszFileName)
|
||||
{
|
||||
return CCLuaScriptModule::sharedLuaScriptModule()->executeScriptFile(pszFileName);
|
||||
}
|
||||
|
||||
// excute script from string
|
||||
bool LuaEngine::excuteString(const char* pszCodes)
|
||||
bool LuaEngine::executeString(const char* pszCodes)
|
||||
{
|
||||
return CCLuaScriptModule::sharedLuaScriptModule()->executeString(pszCodes);
|
||||
}
|
||||
|
|
|
@ -7,12 +7,16 @@
|
|||
#ifdef _WINDOWS
|
||||
|
||||
#undef LUA_DLL
|
||||
|
||||
#if defined(_USRDLL)
|
||||
#define LUA_DLL __declspec(dllexport)
|
||||
#define LUA_DLL __declspec(dllexport)
|
||||
#else /* use a DLL library */
|
||||
#define LUA_DLL __declspec(dllimport)
|
||||
#define LUA_DLL __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define LUA_DLL
|
||||
|
||||
#endif // CC_PLATFORM_WIN32
|
||||
|
||||
class LUA_DLL LuaEngine : public cocos2d::CCScriptEngineProtocol
|
||||
|
@ -20,21 +24,21 @@ class LUA_DLL LuaEngine : public cocos2d::CCScriptEngineProtocol
|
|||
public:
|
||||
|
||||
// functions for excute touch event
|
||||
virtual bool excuteTouchEvent(const char *pszFuncName, cocos2d::CCTouch *pTouch);
|
||||
virtual bool excuteTouchesEvent(const char *pszFuncName, cocos2d::CCSet *pTouches);
|
||||
virtual bool executeTouchEvent(const char *pszFuncName, cocos2d::CCTouch *pTouch);
|
||||
virtual bool executeTouchesEvent(const char *pszFuncName, cocos2d::CCSet *pTouches);
|
||||
|
||||
// functions for CCCallFuncX
|
||||
virtual bool excuteCallFunc(const char *pszFuncName);
|
||||
virtual bool excuteCallFuncN(const char *pszFuncName, cocos2d::CCNode *pNode);
|
||||
virtual bool excuteCallFuncND(const char *pszFuncName, cocos2d::CCNode *pNode, void *pData);
|
||||
virtual bool excuteCallFunc0(const char *pszFuncName, cocos2d::CCObject *pObject);
|
||||
virtual bool executeCallFunc(const char *pszFuncName);
|
||||
virtual bool executeCallFuncN(const char *pszFuncName, cocos2d::CCNode *pNode);
|
||||
virtual bool executeCallFuncND(const char *pszFuncName, cocos2d::CCNode *pNode, void *pData);
|
||||
virtual bool executeCallFunc0(const char *pszFuncName, cocos2d::CCObject *pObject);
|
||||
|
||||
// excute a script function without params
|
||||
virtual bool excuteFuction(const char *pszFuncName);
|
||||
virtual bool executeFuction(const char *pszFuncName);
|
||||
// excute a script file
|
||||
virtual bool excuteScriptFile(const char* pszFileName);
|
||||
virtual bool executeScriptFile(const char* pszFileName);
|
||||
// excute script from string
|
||||
virtual bool excuteString(const char* pszCodes);
|
||||
virtual bool executeString(const char* pszCodes);
|
||||
};
|
||||
|
||||
#endif // __LUA_ENGINE_H__
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "CCLuaSrcipt.h"
|
||||
#include "LuaEngineImpl.h"
|
||||
|
||||
extern "C" {
|
||||
#include "lualib.h"
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef _CCLUASRCIPT_H
|
||||
#define _CCLUASRCIPT_H
|
||||
#ifndef _LUA_ENGINE_IMPL_H
|
||||
#define _LUA_ENGINE_IMPL_H
|
||||
|
||||
#include <string>
|
||||
|
||||
|
@ -162,4 +162,4 @@ private:
|
|||
};
|
||||
|
||||
|
||||
#endif // end of guard _CCLUASRCIPT_H
|
||||
#endif // end of guard _LUA_ENGINE_IMPL_H
|
|
@ -1,17 +1,3 @@
|
|||
# Copyright (C) 2009 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
@ -54,9 +40,10 @@ LOCAL_SRC_FILES :=../src/lapi.c \
|
|||
../tolua/tolua_map.c \
|
||||
../tolua/tolua_push.c \
|
||||
../tolua/tolua_to.c
|
||||
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ \
|
||||
$(LOCAL_PATH)/../src \
|
||||
$(LOCAL_PATH)/../tolua
|
||||
#LOCAL_PRELINK_MODULE := false
|
||||
$(LOCAL_PATH)/../src
|
||||
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
|
|
@ -397,14 +397,6 @@
|
|||
<Filter
|
||||
Name="cocos2dx_support"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\cocos2dx_support\CCLuaSrcipt.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\cocos2dx_support\CCLuaSrcipt.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\cocos2dx_support\LuaCocos2d.cpp"
|
||||
>
|
||||
|
@ -421,6 +413,14 @@
|
|||
RelativePath=".\cocos2dx_support\LuaEngine.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\cocos2dx_support\LuaEngineImpl.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\cocos2dx_support\LuaEngineImpl.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="tolua"
|
||||
|
|
Loading…
Reference in New Issue