mirror of https://github.com/axmolengine/axmol.git
tests run ok when it don't enable lua
This commit is contained in:
parent
a8b6b850de
commit
83e1e0ebd1
|
@ -142,7 +142,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
||||||
|
|
||||||
// run
|
// run
|
||||||
pDirector->runWithScene(pScene);
|
pDirector->runWithScene(pScene);
|
||||||
#endif // CC_ENABLE_LUA
|
#endif // 1
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ LOCAL_SRC_FILES := main.cpp \
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../cocos2dx \
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../cocos2dx \
|
||||||
$(LOCAL_PATH)/../../../../cocos2dx/platform \
|
$(LOCAL_PATH)/../../../../cocos2dx/platform \
|
||||||
$(LOCAL_PATH)/../../../../cocos2dx/include \
|
$(LOCAL_PATH)/../../../../cocos2dx/include \
|
||||||
|
$(LOCAL_PATH)/../../../../cocos2dx/lua_support \
|
||||||
$(LOCAL_PATH)/../../../../CocosDenshion/include \
|
$(LOCAL_PATH)/../../../../CocosDenshion/include \
|
||||||
$(LOCAL_PATH)/../../.. \
|
$(LOCAL_PATH)/../../.. \
|
||||||
$(LOCAL_PATH)/../../../../lua/src \
|
$(LOCAL_PATH)/../../../../lua/src \
|
||||||
|
@ -36,4 +37,6 @@ LOCAL_LDLIBS := -llog -lGLESv1_CM -llog -lz \
|
||||||
|
|
||||||
LOCAL_STATIC_LIBRARIES := libcocos2d libcocosdenshion liblua
|
LOCAL_STATIC_LIBRARIES := libcocos2d libcocosdenshion liblua
|
||||||
|
|
||||||
|
LOCAL_CFLAGS := -DENABLE_LUA
|
||||||
|
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
include $(BUILD_SHARED_LIBRARY)
|
|
@ -1 +1 @@
|
||||||
6499d8743092fb19c5be28ecb550b21e1e6e014b
|
b8a601e0b3a7e29e380e6a4f7edbe86275ed3751
|
|
@ -42,7 +42,7 @@
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="0"
|
Optimization="0"
|
||||||
AdditionalIncludeDirectories="..\..\lua\tolua;..\..\lua\src;"$(SolutionDir)cocos2dx\platform";"$(SolutionDir)cocos2dx\include";"$(SolutionDir)cocos2dx";"$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES";..\;.\"
|
AdditionalIncludeDirectories="..\..\lua\tolua;..\..\lua\src;"$(SolutionDir)cocos2dx\platform";"$(SolutionDir)cocos2dx\include";"$(SolutionDir)cocos2dx";"$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES";..\;.\"
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;ENABLE_LUA"
|
||||||
MinimalRebuild="true"
|
MinimalRebuild="true"
|
||||||
BasicRuntimeChecks="3"
|
BasicRuntimeChecks="3"
|
||||||
RuntimeLibrary="3"
|
RuntimeLibrary="3"
|
||||||
|
|
|
@ -19,6 +19,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "tests\test.win32\t
|
||||||
ProjectSection(ProjectDependencies) = postProject
|
ProjectSection(ProjectDependencies) = postProject
|
||||||
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}
|
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E} = {98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}
|
||||||
{207BC7A9-CCF1-4F2F-A04D-45F72242AE25} = {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}
|
{207BC7A9-CCF1-4F2F-A04D-45F72242AE25} = {207BC7A9-CCF1-4F2F-A04D-45F72242AE25}
|
||||||
|
{A9376AC9-4D65-498F-885D-EEC3B41DD6E8} = {A9376AC9-4D65-498F-885D-EEC3B41DD6E8}
|
||||||
{929480E7-23C0-4DF6-8456-096D71547116} = {929480E7-23C0-4DF6-8456-096D71547116}
|
{929480E7-23C0-4DF6-8456-096D71547116} = {929480E7-23C0-4DF6-8456-096D71547116}
|
||||||
{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}
|
{F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6} = {F8EDD7FA-9A51-4E80-BAEB-860825D2EAC6}
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
|
|
|
@ -99,13 +99,14 @@ touch_dispatcher/CCTouchDispatcher.cpp \
|
||||||
touch_dispatcher/CCTouchHandler.cpp
|
touch_dispatcher/CCTouchHandler.cpp
|
||||||
|
|
||||||
ifeq ($(ENABLE_LUA), true)
|
ifeq ($(ENABLE_LUA), true)
|
||||||
LOCAL_SRC_FILES += Ndscript/CCLuaSrcipt.cpp \
|
LOCAL_SRC_FILES += lua_support/CCLuaSrcipt.cpp \
|
||||||
Ndscript/LuaCocos2d.cpp \
|
lua_support/LuaCocos2d.cpp \
|
||||||
NdControls/NdCxList.cpp \
|
NdControls/NdCxList.cpp \
|
||||||
NdControls/NdCxListItem.cpp
|
NdControls/NdCxListItem.cpp
|
||||||
|
|
||||||
LOCAL_CFLAGS := -DENABLE_LUA -DUSE_FILE32API
|
LOCAL_CFLAGS := -DENABLE_LUA -DUSE_FILE32API
|
||||||
else
|
else
|
||||||
|
# define the macro to compile through support/zip_support/ioapi.c
|
||||||
LOCAL_CFLAGS := -DUSE_FILE32API
|
LOCAL_CFLAGS := -DUSE_FILE32API
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -132,7 +133,6 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/ \
|
||||||
$(LOCAL_PATH)/../lua/src \
|
$(LOCAL_PATH)/../lua/src \
|
||||||
$(LOCAL_PATH)/../lua/tolua
|
$(LOCAL_PATH)/../lua/tolua
|
||||||
|
|
||||||
# define the macro to compile through support/zip_support/ioapi.c
|
|
||||||
LOCAL_CFLAGS := -DUSE_FILE32API
|
|
||||||
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
include $(BUILD_STATIC_LIBRARY)
|
||||||
|
|
|
@ -1,535 +0,0 @@
|
||||||
#include "CCLuaSrcipt.h"
|
|
||||||
#ifdef ENABLE_LUA
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "lualib.h"
|
|
||||||
#include "lauxlib.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#include "tolua++.h"
|
|
||||||
#include "CCTouch.h"
|
|
||||||
#include "CCNode.h"
|
|
||||||
#include "CCObject.h"
|
|
||||||
#include "LuaCocos2d.h"
|
|
||||||
namespace cocos2d
|
|
||||||
{
|
|
||||||
|
|
||||||
CCLuaScriptModule* CCLuaScriptModule::s_luaScriptModule = NULL;
|
|
||||||
|
|
||||||
CCLuaScriptModule* CCLuaScriptModule::sharedLuaScriptModule(void)
|
|
||||||
{
|
|
||||||
if (s_luaScriptModule == NULL)
|
|
||||||
{
|
|
||||||
s_luaScriptModule = new CCLuaScriptModule();
|
|
||||||
}
|
|
||||||
return s_luaScriptModule;
|
|
||||||
}
|
|
||||||
void CCLuaScriptModule::purgeSharedLuaScriptModule()
|
|
||||||
{
|
|
||||||
s_luaScriptModule->release();
|
|
||||||
s_luaScriptModule = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Constructor (creates Lua state)
|
|
||||||
*************************************************************************/
|
|
||||||
CCLuaScriptModule::CCLuaScriptModule()
|
|
||||||
{
|
|
||||||
|
|
||||||
d_ownsState = true;
|
|
||||||
d_state = lua_open();
|
|
||||||
luaL_openlibs(d_state);
|
|
||||||
int nOpen = tolua_Cocos2d_open(d_state);
|
|
||||||
// init all standard libraries
|
|
||||||
/*luaopen_base(d_state);
|
|
||||||
luaopen_io(d_state);
|
|
||||||
luaopen_string(d_state);
|
|
||||||
luaopen_table(d_state);
|
|
||||||
luaopen_math(d_state);
|
|
||||||
*/
|
|
||||||
//luaopen_debug(d_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Constructor (uses given Lua state)
|
|
||||||
*************************************************************************/
|
|
||||||
CCLuaScriptModule::CCLuaScriptModule(lua_State* state)
|
|
||||||
{
|
|
||||||
// just use the given state
|
|
||||||
d_ownsState = false;
|
|
||||||
d_state = state;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Destructor
|
|
||||||
*************************************************************************/
|
|
||||||
CCLuaScriptModule::~CCLuaScriptModule()
|
|
||||||
{
|
|
||||||
if ( d_ownsState && d_state )
|
|
||||||
{
|
|
||||||
lua_close( d_state );
|
|
||||||
}
|
|
||||||
s_luaScriptModule = NULL;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Execute script file
|
|
||||||
*************************************************************************/
|
|
||||||
void CCLuaScriptModule::executeScriptFile(const std::string& filename)
|
|
||||||
{
|
|
||||||
int nRet = luaL_dofile(d_state,filename.c_str());
|
|
||||||
if (nRet != 0)
|
|
||||||
{
|
|
||||||
CCLog("executeScriptFile Error nRet = %d", nRet);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Execute global script function
|
|
||||||
*************************************************************************/
|
|
||||||
int CCLuaScriptModule::executeScriptGlobal(const std::string& function_name)
|
|
||||||
{
|
|
||||||
// get the function from lua
|
|
||||||
lua_getglobal(d_state, function_name.c_str());
|
|
||||||
// is it a function
|
|
||||||
if ( !lua_isfunction(d_state,-1) )
|
|
||||||
{
|
|
||||||
CCLog("name does not represent a Lua function");
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// call it
|
|
||||||
int error = lua_pcall(d_state,0,1,0);
|
|
||||||
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
std::string msg = lua_tostring(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
CCLog("%s", msg.c_str());
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get return value
|
|
||||||
if ( !lua_isnumber(d_state,-1) )
|
|
||||||
{
|
|
||||||
CCLog("return value is not a number %s", function_name.c_str());
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = (int)lua_tonumber(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
|
|
||||||
// return it
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Execute scripted event handler
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
bool CCLuaScriptModule::executeSchedule(const std::string& handler_name, ccTime cc)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (handler_name.size() == 0)
|
|
||||||
{
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: handler_name == NULL\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the function from lua
|
|
||||||
lua_getglobal(d_state, handler_name.c_str());
|
|
||||||
|
|
||||||
// is it a function
|
|
||||||
if ( !lua_isfunction(d_state,-1) )
|
|
||||||
{
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name+"\n\n"+"name does not represent a Lua function"+"\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __FILE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// push EventArgs as the first parameter
|
|
||||||
//tolua_pushusertype(d_state,(void*)&cc,"dFloat");
|
|
||||||
lua_pushfstring(d_state, "%f", cc);
|
|
||||||
|
|
||||||
// call it
|
|
||||||
int error = lua_pcall(d_state,1,0,0);
|
|
||||||
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
std::string msg = lua_tostring(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msgerror = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name+"\n\n"+msg+"\n";
|
|
||||||
CCLog("%s %d", msgerror.c_str(), __FILE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// return it
|
|
||||||
return true;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
bool CCLuaScriptModule::executeCallFunc(const std::string& handler_name)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (handler_name.size() == 0)
|
|
||||||
{
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler:handler_name == NULL\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
lua_getglobal(d_state, handler_name.c_str());
|
|
||||||
|
|
||||||
// is it a function
|
|
||||||
if ( !lua_isfunction(d_state,-1) )
|
|
||||||
{
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name + "name does not represent a Lua functio"+"\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// push EventArgs as the first parameter
|
|
||||||
//tolua_pushusertype(d_state,(void*)&cc,"cocos2d::ccTime");
|
|
||||||
// call it
|
|
||||||
int error = lua_pcall(d_state,0,0,0);
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
std::string msg = lua_tostring(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msgerror = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name + msg +"\n";
|
|
||||||
CCLog("%s %d", msgerror.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// return it
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
bool CCLuaScriptModule::executeCallFuncN(const std::string& handler_name, CCNode* pNode)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (handler_name.size() == 0)
|
|
||||||
{
|
|
||||||
std::string msg = "(executeCallFuncN) Unable to execute scripted event handler: handler_name == NULL\n";
|
|
||||||
CCLog("%s %d ", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
lua_getglobal(d_state, handler_name.c_str());
|
|
||||||
|
|
||||||
|
|
||||||
// is it a function
|
|
||||||
if ( !lua_isfunction(d_state,-1) )
|
|
||||||
{
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msg = "(executeCallFuncN) Unable to execute scripted event handler: "+handler_name +"name does not represent a Lua function"+"\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// push EventArgs as the first parameter
|
|
||||||
tolua_pushusertype(d_state,(void*)pNode,"cocos2d::CCNode");
|
|
||||||
// call it
|
|
||||||
int error = lua_pcall(d_state,1,0,0);
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
std::string msg = lua_tostring(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msgerror = "(executeCallFuncN) Unable to execute scripted event handler: "+handler_name +msg+"\n";
|
|
||||||
CCLog("%s %d", msgerror.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// return it
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
bool CCLuaScriptModule::executeCallFuncND(const std::string& handler_name, CCNode* pNode, void*pData)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
if (handler_name.size() == 0)
|
|
||||||
{
|
|
||||||
std::string msg = "(executeCallFuncND) Unable to execute scripted event handler: handler_name == NULL\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// get the function from lua
|
|
||||||
lua_getglobal(d_state, handler_name.c_str());
|
|
||||||
|
|
||||||
// is it a function
|
|
||||||
if ( !lua_isfunction(d_state,-1) )
|
|
||||||
{
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msg = "(executeCallFuncND) Unable to execute scripted event handler: "+handler_name +"name does not represent a Lua function"+"\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// push EventArgs as the first parameter
|
|
||||||
tolua_pushusertype(d_state,(void*)pNode,"cocos2d::CCNode");
|
|
||||||
tolua_pushusertype(d_state,(void*)pData,"void*");
|
|
||||||
// call it
|
|
||||||
int error = lua_pcall(d_state,2,0,0);
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
std::string msg = lua_tostring(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msgerror = "(executeCallFuncND) Unable to execute scripted event handler: "+handler_name +msg+"\n";
|
|
||||||
CCLog("%s %d", msgerror.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// return it
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
bool CCLuaScriptModule::executeMenuHandler(const std::string& handler_name, CCObject* pobj)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (handler_name.size() == 0)
|
|
||||||
{
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: handler_name == NULL\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// get the function from lua
|
|
||||||
lua_getglobal(d_state, handler_name.c_str());
|
|
||||||
|
|
||||||
// is it a function
|
|
||||||
if ( !lua_isfunction(d_state,-1) )
|
|
||||||
{
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name + "name does not represent a Lua function"+"\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// push EventArgs as the first parameter
|
|
||||||
tolua_pushusertype(d_state,(void*)pobj,"cocos2d::CCObject");
|
|
||||||
// call it
|
|
||||||
int error = lua_pcall(d_state,1,0,0);
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
std::string msg = lua_tostring(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
std::string msgerror = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name +msg+"\n";
|
|
||||||
CCLog("%s %d", msgerror.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// return it
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CCLuaScriptModule::executeTouchesEvent(const std::string& handler_name, CCSet *pobj)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (handler_name.size() == 0)
|
|
||||||
{
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: handler_name == null\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// get the function from lua
|
|
||||||
lua_getglobal(d_state, handler_name.c_str());
|
|
||||||
|
|
||||||
// is it a function
|
|
||||||
if ( !lua_isfunction(d_state,-1) )
|
|
||||||
{
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name+"name does not represent a Lua function"+"\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// push EventArgs as the first parameter
|
|
||||||
tolua_pushusertype(d_state,(void*)pobj,"cocos2d::CCSet");
|
|
||||||
// call it
|
|
||||||
int error = lua_pcall(d_state,1,0,0);
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
std::string msg = lua_tostring(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msgerror = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name+msg+"\n";
|
|
||||||
CCLog("%s %d", msgerror.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// return it
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CCLuaScriptModule::executeTouch(const std::string& handler_name, CCTouch *pobj)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (handler_name.size() == 0)
|
|
||||||
{
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: handler_name == null\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// get the function from lua
|
|
||||||
lua_getglobal(d_state, handler_name.c_str());
|
|
||||||
|
|
||||||
// is it a function
|
|
||||||
if ( !lua_isfunction(d_state,-1) )
|
|
||||||
{
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name+"\n\n"+"name does not represent a Lua function"+"\n";
|
|
||||||
CCLog("%s ", msg.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// push EventArgs as the first parameter
|
|
||||||
tolua_pushusertype(d_state,(void*)pobj,"cocos2d::CCTouch");
|
|
||||||
// call it
|
|
||||||
int error = lua_pcall(d_state,1,0,0);
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
std::string msg = lua_tostring(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
std::string msgerror = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name+"\n\n"+msg+"\n";
|
|
||||||
CCLog("%s ", msgerror.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// return it
|
|
||||||
return true;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
bool CCLuaScriptModule::executeEventHandler(const std::string& handler_name, CCEvent* pEvent)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (handler_name.size() == 0)
|
|
||||||
{
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: handler_name == NULL\n";
|
|
||||||
CCLog("%s ", msg.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// get the function from lua
|
|
||||||
lua_getglobal(d_state, handler_name.c_str());
|
|
||||||
|
|
||||||
// is it a function
|
|
||||||
if ( !lua_isfunction(d_state,-1) )
|
|
||||||
{
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msg = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name+"\n\n"+"name does not represent a Lua function"+"\n";
|
|
||||||
CCLog("%s ", msg.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// push EventArgs as the first parameter
|
|
||||||
tolua_pushusertype(d_state,(void*)pEvent,"cocos2d::CCEvent");
|
|
||||||
// call it
|
|
||||||
int error = lua_pcall(d_state,1,0,0);
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
std::string msg = lua_tostring(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msgerror = "(LuaScriptModule) Unable to execute scripted event handler: "+handler_name+"\n\n"+msg+"\n";
|
|
||||||
CCLog("%s ", msgerror.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// return it
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CCLuaScriptModule::executeListItem(const std::string& handler_name, int index, CCObject* pobj)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (handler_name.size() == 0)
|
|
||||||
{
|
|
||||||
std::string msg = "(CCLuaScriptModule) Unable to execute scripted event handler: handler_name == NULL\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// get the function from lua
|
|
||||||
lua_getglobal(d_state, handler_name.c_str());
|
|
||||||
|
|
||||||
// is it a function
|
|
||||||
if ( !lua_isfunction(d_state,-1) )
|
|
||||||
{
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msg = "(CCLuaScriptModule) Unable to execute scripted event handler: "+handler_name +"name does not represent a Lua function"+"\n";
|
|
||||||
CCLog("%s %d", msg.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// push EventArgs as the first parameter
|
|
||||||
lua_pushfstring(d_state, "%d", index);
|
|
||||||
tolua_pushusertype(d_state,(void*)pobj,"cocos2d::CCObject");
|
|
||||||
// call it
|
|
||||||
int error = lua_pcall(d_state,2,0,0);
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
std::string msg = lua_tostring(d_state,-1);
|
|
||||||
lua_pop(d_state,1);
|
|
||||||
lua_settop( d_state, 0 );
|
|
||||||
std::string msgerror = "(CCLuaScriptModule) Unable to execute scripted event handler: "+handler_name +msg+"\n";
|
|
||||||
CCLog("%s %d", msgerror.c_str(), __LINE__);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// return it
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Execute script code string
|
|
||||||
*************************************************************************/
|
|
||||||
void CCLuaScriptModule::executeString(const std::string& str)
|
|
||||||
{
|
|
||||||
// load code into lua and call it
|
|
||||||
int error = luaL_dostring(d_state, str.c_str());
|
|
||||||
|
|
||||||
// handle errors
|
|
||||||
if ( error )
|
|
||||||
{
|
|
||||||
CCLog("executeString %d", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Create Lua bindings
|
|
||||||
*************************************************************************/
|
|
||||||
void CCLuaScriptModule::createBindings(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
//tolua_Cocos2d_open(d_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Destroy Lua bindings
|
|
||||||
*************************************************************************/
|
|
||||||
void CCLuaScriptModule::destroyBindings(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
lua_pushnil(d_state);
|
|
||||||
lua_setglobal(d_state,"cocos2d");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace CEGUI
|
|
||||||
|
|
||||||
#endif //CC_ENABLE_LUA
|
|
|
@ -1,175 +0,0 @@
|
||||||
#ifndef _CCLUASRCIPT_H
|
|
||||||
#define _CCLUASRCIPT_H
|
|
||||||
#include "ccConfig.h"
|
|
||||||
|
|
||||||
#ifdef ENABLE_LUA
|
|
||||||
#include "CCCommon.h"
|
|
||||||
#include "CCObject.h"
|
|
||||||
#include <string>
|
|
||||||
#include "ccTypes.h"
|
|
||||||
// include Lua
|
|
||||||
extern "C" {
|
|
||||||
#include "lua.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace cocos2d
|
|
||||||
{
|
|
||||||
class CCEvent;
|
|
||||||
class CCNode;
|
|
||||||
class CCObject;
|
|
||||||
|
|
||||||
class CC_DLL CCLuaScriptModule : public CCObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/*************************************************************************
|
|
||||||
Construction and Destruction
|
|
||||||
*************************************************************************/
|
|
||||||
/*!
|
|
||||||
\brief
|
|
||||||
Constructor for LuaScriptModule class which create a lua_State
|
|
||||||
*/
|
|
||||||
CCLuaScriptModule();
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief
|
|
||||||
Constructor for LuaScriptModule class which takes a lua_State
|
|
||||||
|
|
||||||
\param state
|
|
||||||
Pointer to the lua_State that the script module should attach to.
|
|
||||||
*/
|
|
||||||
CCLuaScriptModule(lua_State* state);
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief
|
|
||||||
Destructor for LuaScriptModule class.
|
|
||||||
*/
|
|
||||||
virtual ~CCLuaScriptModule();
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Script Execution Functions
|
|
||||||
*************************************************************************/
|
|
||||||
/*!
|
|
||||||
\brief
|
|
||||||
Execute a script file.
|
|
||||||
|
|
||||||
\param filename
|
|
||||||
String object holding the filename of the script file that is to be executed
|
|
||||||
|
|
||||||
*/
|
|
||||||
void executeScriptFile(const std::string& filename);
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief
|
|
||||||
Execute a scripted global function. The function should not take any parameters and should return an integer.
|
|
||||||
|
|
||||||
\param function_name
|
|
||||||
String object holding the name of the function, in the global script environment, that
|
|
||||||
is to be executed.
|
|
||||||
|
|
||||||
\return
|
|
||||||
The integer value returned from the script function.
|
|
||||||
*/
|
|
||||||
int executeScriptGlobal(const std::string& function_name);
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief
|
|
||||||
Execute a scripted global 'event handler' function. The function should take some kind of EventArgs like parameter
|
|
||||||
that the concrete implementation of this function can create from the passed EventArgs based object. The function
|
|
||||||
should not return anything.
|
|
||||||
|
|
||||||
\param handler_name
|
|
||||||
String object holding the name of the scripted handler function.
|
|
||||||
|
|
||||||
\param e
|
|
||||||
EventArgs based object that should be passed, by any appropriate means, to the scripted function.
|
|
||||||
|
|
||||||
\return
|
|
||||||
- true if the event was handled.
|
|
||||||
- false if the event was not handled.
|
|
||||||
*/
|
|
||||||
bool executeSchedule(const std::string& handler_name, ccTime cc);
|
|
||||||
bool executeCallFunc(const std::string& handler_name);
|
|
||||||
bool executeCallFuncN(const std::string& handler_name, CCNode* pNode);
|
|
||||||
bool executeCallFuncND(const std::string& handler_name, CCNode* pNode, void*pData);
|
|
||||||
bool executeMenuHandler(const std::string& handler_name, CCObject* pobj);
|
|
||||||
bool executeEventHandler(const std::string& handler_name, CCEvent* pEvent);
|
|
||||||
bool executeTouchesEvent(const std::string& handler_name, CCSet *pobj);
|
|
||||||
bool executeTouch(const std::string& handler_name, CCTouch *pobj);
|
|
||||||
bool executeListItem(const std::string& handler_name, int index, CCObject* pobj);
|
|
||||||
/*!
|
|
||||||
\brief
|
|
||||||
Execute script code contained in the given CEGUI::String object.
|
|
||||||
|
|
||||||
\param str
|
|
||||||
String object holding the valid script code that should be executed.
|
|
||||||
|
|
||||||
\return
|
|
||||||
Nothing.
|
|
||||||
*/
|
|
||||||
void executeString(const std::string& str);
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Bindings creation / destruction
|
|
||||||
*************************************************************************/
|
|
||||||
/*!
|
|
||||||
\brief
|
|
||||||
Method called during system initialisation, prior to running any scripts via the ScriptModule, to enable the ScriptModule
|
|
||||||
to perform any operations required to complete initialisation or binding of the script language to the gui system objects.
|
|
||||||
|
|
||||||
\return
|
|
||||||
Nothing.
|
|
||||||
*/
|
|
||||||
void createBindings(void);
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief
|
|
||||||
Method called during system destruction, after all scripts have been run via the ScriptModule, to enable the ScriptModule
|
|
||||||
to perform any operations required to cleanup bindings of the script language to the gui system objects, as set-up in the
|
|
||||||
earlier createBindings call.
|
|
||||||
|
|
||||||
\return
|
|
||||||
Nothing.
|
|
||||||
*/
|
|
||||||
void destroyBindings(void);
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
Accessor type functions
|
|
||||||
*************************************************************************/
|
|
||||||
/*!
|
|
||||||
\brief
|
|
||||||
Method used to get a pointer to the lua_State that the script module is attached to.
|
|
||||||
|
|
||||||
\return
|
|
||||||
A pointer to the lua_State that the script module is attached to.
|
|
||||||
*/
|
|
||||||
lua_State* getLuaState(void) const {return d_state;}
|
|
||||||
|
|
||||||
|
|
||||||
static CCLuaScriptModule* sharedLuaScriptModule(void);
|
|
||||||
|
|
||||||
static void purgeSharedLuaScriptModule();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
static CCLuaScriptModule* s_luaScriptModule;
|
|
||||||
/*************************************************************************
|
|
||||||
Implementation Data
|
|
||||||
*************************************************************************/
|
|
||||||
bool d_ownsState; //!< true when the attached lua_State was created by this script module
|
|
||||||
lua_State* d_state; //!< The lua_State that this script module uses.
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace cocos2d
|
|
||||||
|
|
||||||
#endif //CC_ENABLE_LUA
|
|
||||||
#endif // end of guard _CCLUASRCIPT_H
|
|
|
@ -1 +0,0 @@
|
||||||
1139f1b8e60225b4e38fae58ee8da9c24e27d8c9
|
|
|
@ -1,24 +0,0 @@
|
||||||
#ifndef LUACOCOS2D_H
|
|
||||||
#define LUACOCOS2D_H
|
|
||||||
#include "cocos2d.h"
|
|
||||||
#ifdef ENABLE_LUA
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "lua.h"
|
|
||||||
#include "CCKeypadDispatcher.h"
|
|
||||||
#include "CCRibbon.h"
|
|
||||||
#include "CCParallaxNode.h"
|
|
||||||
#include "CCAutoreleasePool.h"
|
|
||||||
#include "CCIMEDispatcher.h"
|
|
||||||
#include "CCMutableArray.h"
|
|
||||||
#include "../NdControls/NdCxList.h"
|
|
||||||
#include "../NdControls/NdCxListItem.h"
|
|
||||||
#include "../NdControls/ControlDefine.h"
|
|
||||||
//#define TOLUA_RELEASE
|
|
||||||
#if defined(_WIN32) && defined(_DEBUG)
|
|
||||||
#pragma warning (disable:4800)
|
|
||||||
#endif
|
|
||||||
using namespace cocos2d;
|
|
||||||
using namespace NdCxControl;
|
|
||||||
int tolua_Cocos2d_open(lua_State* tolua_S);
|
|
||||||
#endif
|
|
||||||
#endif//LUACOCOS2D_H
|
|
|
@ -31,7 +31,7 @@ THE SOFTWARE.
|
||||||
#ifdef ENABLE_LUA
|
#ifdef ENABLE_LUA
|
||||||
#include "CCMutableDictionary.h"
|
#include "CCMutableDictionary.h"
|
||||||
#include "CCString.h"
|
#include "CCString.h"
|
||||||
#include "../Ndscript/CCLuaSrcipt.h"
|
#include "../lua_support/CCLuaSrcipt.h"
|
||||||
#endif
|
#endif
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
|
|
@ -271,6 +271,4 @@ To enable set it to a value different than 0. Disabled by default.
|
||||||
#define CC_IS_RETINA_DISPLAY_SUPPORTED 0
|
#define CC_IS_RETINA_DISPLAY_SUPPORTED 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CC_ENABLE_LUA 1
|
|
||||||
|
|
||||||
#endif // __CCCONFIG_H__
|
#endif // __CCCONFIG_H__
|
||||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifdef ENABLE_LUA
|
#ifdef ENABLE_LUA
|
||||||
#include "../Ndscript/CCLuaSrcipt.h"
|
#include "../lua_support/CCLuaSrcipt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="0"
|
Optimization="0"
|
||||||
AdditionalIncludeDirectories="..\..\lua\tolua;..\..\lua\src;..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\OGLES;..\include;.."
|
AdditionalIncludeDirectories="..\..\lua\tolua;..\..\lua\src;..\platform;..\platform\third_party\win32\iconv;..\platform\third_party\win32\zlib;..\platform\third_party\win32\libpng;..\platform\third_party\win32\libjpeg;..\platform\third_party\win32\libxml2;..\platform\third_party\win32\OGLES;..\include;.."
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES"
|
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES;ENABLE_LUA"
|
||||||
MinimalRebuild="true"
|
MinimalRebuild="true"
|
||||||
BasicRuntimeChecks="3"
|
BasicRuntimeChecks="3"
|
||||||
RuntimeLibrary="3"
|
RuntimeLibrary="3"
|
||||||
|
@ -1081,22 +1081,22 @@
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="NDScript"
|
Name="lua_support"
|
||||||
>
|
>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\Ndscript\CCLuaSrcipt.cpp"
|
RelativePath="..\lua_support\CCLuaSrcipt.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\Ndscript\CCLuaSrcipt.h"
|
RelativePath="..\lua_support\CCLuaSrcipt.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\Ndscript\LuaCocos2d.cpp"
|
RelativePath="..\lua_support\LuaCocos2d.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\Ndscript\LuaCocos2d.h"
|
RelativePath="..\lua_support\LuaCocos2d.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
|
|
@ -46,10 +46,6 @@ public class TestsDemo extends Cocos2dxActivity{
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("cocosdenshion");
|
|
||||||
System.loadLibrary("chipmunk");
|
|
||||||
System.loadLibrary("box2d");
|
|
||||||
System.loadLibrary("cocos2d");
|
|
||||||
System.loadLibrary("tests");
|
System.loadLibrary("tests");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCCLCompilerTool"
|
Name="VCCLCompilerTool"
|
||||||
Optimization="0"
|
Optimization="0"
|
||||||
AdditionalIncludeDirectories=""$(SolutionDir)cocos2dx\platform\third_party\win32";"$(SolutionDir)cocos2dx\platform";"$(SolutionDir)cocos2dx";"$(SolutionDir)cocos2dx\include";"$(SolutionDir)";"$(SolutionDir)chipmunk\include\chipmunk";"$(SolutionDir)CocosDenshion\include";..\tests;"$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES";..\;.\"
|
AdditionalIncludeDirectories=""$(SolutionDir)cocos2dx\platform\third_party\win32";..\..\lua\tolua;..\..\lua\src;"$(SolutionDir)cocos2dx\platform";"$(SolutionDir)cocos2dx";"$(SolutionDir)cocos2dx\include";"$(SolutionDir)";"$(SolutionDir)chipmunk\include\chipmunk";"$(SolutionDir)CocosDenshion\include";..\tests;"$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES";..\;.\"
|
||||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES"
|
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_MATH_DEFINES;GL_GLEXT_PROTOTYPES"
|
||||||
MinimalRebuild="true"
|
MinimalRebuild="true"
|
||||||
BasicRuntimeChecks="3"
|
BasicRuntimeChecks="3"
|
||||||
|
|
Loading…
Reference in New Issue