issue #10107: Binding AnimationInfo to lua

This commit is contained in:
samuele3hu 2015-01-21 10:06:48 +08:00
parent d4db54dc64
commit 666af29681
10 changed files with 174 additions and 4 deletions

View File

@ -93,6 +93,7 @@ set(lua_bindings_manual_files
manual/cocosdenshion/lua_cocos2dx_cocosdenshion_manual.cpp
manual/cocostudio/CustomGUIReader.cpp
manual/cocostudio/lua_cocos2dx_coco_studio_manual.cpp
manual/cocostudio/lua-coco-studio-conversions.cpp
manual/cocostudio/lua_cocos2dx_csloader_manual.cpp
manual/controller/lua_cocos2dx_controller_manual.cpp
manual/extension/lua_cocos2dx_extension_manual.cpp

View File

@ -0,0 +1,89 @@
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "lua-coco-studio-conversions.h"
#include "ActionTimeline/CCActionTimeline.h"
#if COCOS2D_DEBUG >=1
extern void luaval_to_native_err(lua_State* L,const char* msg,tolua_Error* err, const char* funcName);
#endif
bool luaval_to_animationInfo(lua_State* L, int lo, cocostudio::timeline::AnimationInfo* outValue , const char* funcName)
{
if (nullptr == L || nullptr == outValue)
return false;
bool ok = true;
tolua_Error tolua_err;
if (!tolua_istable(L, lo, 0, &tolua_err) )
{
#if COCOS2D_DEBUG >=1
luaval_to_native_err(L,"#ferror:",&tolua_err,funcName);
#endif
ok = false;
}
if (ok)
{
lua_pushstring(L, "name"); /* L: paramStack key */
lua_gettable(L,lo); /* L: paramStack paramStack[lo][key] */
outValue->name = lua_isstring(L, -1)? lua_tostring(L, -1) : "";
lua_pop(L,1); /* L: paramStack*/
lua_pushstring(L, "startIndex");
lua_gettable(L,lo);
outValue->startIndex = lua_isnumber(L, -1)?(int)lua_tonumber(L, -1) : 0;
lua_pop(L,1);
lua_pushstring(L, "endIndex");
lua_gettable(L, lo);
outValue->endIndex = lua_isnumber(L, -1)?(int)lua_tonumber(L, -1) : 0;
lua_pop(L, 1);
return true;
}
return false;
}
void animationInfo_to_luaval(lua_State* L,const cocostudio::timeline::AnimationInfo& inValue)
{
if (nullptr == L)
return;
lua_newtable(L);
lua_pushstring(L, "name");
lua_pushstring(L, inValue.name.c_str());
lua_rawset(L, -3);
lua_pushstring(L, "startIndex");
lua_pushnumber(L, (lua_Number)inValue.startIndex);
lua_rawset(L, -3);
lua_pushstring(L, "endIndex");
lua_pushnumber(L, (lua_Number)inValue.endIndex);
lua_rawset(L, -3);
}

View File

@ -0,0 +1,47 @@
/****************************************************************************
Copyright (c) 2013-2015 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __COCOS_SCRIPTING_LUA_BINDING_MANUAL_COCOSTUDIO_LUA_STUDIO_CONVERSIONS_H__
#define __COCOS_SCRIPTING_LUA_BINDING_MANUAL_COCOSTUDIO_LUA_STUDIO_CONVERSIONS_H__
extern "C" {
#include "lua.h"
#include "tolua++.h"
}
#include "tolua_fix.h"
namespace cocostudio
{
namespace timeline
{
struct AnimationInfo;
}
}
extern bool luaval_to_animationInfo(lua_State* L, int lo, cocostudio::timeline::AnimationInfo* outValue , const char* funcName = "");
extern void animationInfo_to_luaval(lua_State* L,const cocostudio::timeline::AnimationInfo& inValue);
#endif //__COCOS_SCRIPTING_LUA_BINDING_MANUAL_COCOSTUDIO_LUA_STUDIO_CONVERSIONS_H__

View File

@ -97,7 +97,8 @@ LOCAL_SRC_FILES += ../manual/cocostudio/lua_cocos2dx_coco_studio_manual.cpp \
../manual/cocostudio/CustomGUIReader.cpp \
../manual/cocostudio/lua_cocos2dx_csloader_manual.cpp \
../auto/lua_cocos2dx_csloader_auto.cpp \
../auto/lua_cocos2dx_studio_auto.cpp
../auto/lua_cocos2dx_studio_auto.cpp \
../manual/cocostudio/lua-coco-studio-conversions.cpp
#spine
LOCAL_SRC_FILES += ../manual/spine/lua_cocos2dx_spine_manual.cpp \

View File

@ -165,6 +165,10 @@
15AC69E21987712500D17520 /* tolua_event.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ABCA1FA18CD8F6E0087CE3A /* tolua_event.h */; };
15AC69E31987712500D17520 /* tolua++.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ABCA1FF18CD8F6E0087CE3A /* tolua++.h */; };
15AC69E4198771FF00D17520 /* libluajit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1ABCA1F618CD8F5F0087CE3A /* libluajit.a */; };
15B575491A6E9AF300041C20 /* lua-coco-studio-conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15B575471A6E9AF300041C20 /* lua-coco-studio-conversions.cpp */; };
15B5754A1A6E9AF300041C20 /* lua-coco-studio-conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15B575471A6E9AF300041C20 /* lua-coco-studio-conversions.cpp */; };
15B5754B1A6E9AF300041C20 /* lua-coco-studio-conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = 15B575481A6E9AF300041C20 /* lua-coco-studio-conversions.h */; };
15B5754C1A6E9AF300041C20 /* lua-coco-studio-conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = 15B575481A6E9AF300041C20 /* lua-coco-studio-conversions.h */; };
15C1C2CD1987495500A46ACC /* lua_cocos2dx_auto.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AACE74918BC45C200215002 /* lua_cocos2dx_auto.cpp */; };
15C1C2CE1987498B00A46ACC /* LuaOpengl.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15C1C24F198747E400A46ACC /* LuaOpengl.cpp */; };
15C1C2CF1987498B00A46ACC /* lua_cocos2dx_deprecated.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 15C1BCD31986525900A46ACC /* lua_cocos2dx_deprecated.cpp */; };
@ -329,6 +333,8 @@
159552391A25E1C5001E9FC9 /* lua_cocos2dx_csloader_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_csloader_auto.hpp; sourceTree = "<group>"; };
1595523E1A25E4B8001E9FC9 /* lua_cocos2dx_csloader_manual.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_csloader_manual.cpp; sourceTree = "<group>"; };
1595523F1A25E4B8001E9FC9 /* lua_cocos2dx_csloader_manual.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_csloader_manual.hpp; sourceTree = "<group>"; };
15B575471A6E9AF300041C20 /* lua-coco-studio-conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "lua-coco-studio-conversions.cpp"; sourceTree = "<group>"; };
15B575481A6E9AF300041C20 /* lua-coco-studio-conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "lua-coco-studio-conversions.h"; sourceTree = "<group>"; };
15C1BCC019864D8700A46ACC /* lua_cocos2dx_cocosbuilder_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_cocosbuilder_auto.cpp; sourceTree = "<group>"; };
15C1BCC119864D8700A46ACC /* lua_cocos2dx_cocosbuilder_auto.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lua_cocos2dx_cocosbuilder_auto.hpp; sourceTree = "<group>"; };
15C1BCC219864D8700A46ACC /* lua_cocos2dx_cocosdenshion_auto.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lua_cocos2dx_cocosdenshion_auto.cpp; sourceTree = "<group>"; };
@ -573,6 +579,8 @@
15EFA400198B2AB2000C57D3 /* cocostudio */ = {
isa = PBXGroup;
children = (
15B575471A6E9AF300041C20 /* lua-coco-studio-conversions.cpp */,
15B575481A6E9AF300041C20 /* lua-coco-studio-conversions.h */,
1595523E1A25E4B8001E9FC9 /* lua_cocos2dx_csloader_manual.cpp */,
1595523F1A25E4B8001E9FC9 /* lua_cocos2dx_csloader_manual.hpp */,
566F015D19B5EB0F00FCA620 /* CustomGUIReader.cpp */,
@ -851,6 +859,7 @@
15C1C2DC19874B4400A46ACC /* xxtea.h in Headers */,
15415AD319A71A53004F1E71 /* timeout.h in Headers */,
15C1C2D5198749BC00A46ACC /* LuaOpengl.h in Headers */,
15B5754B1A6E9AF300041C20 /* lua-coco-studio-conversions.h in Headers */,
155C7E2819A71CE600F08B25 /* lua_cocos2dx_ui_manual.hpp in Headers */,
15C1C2D6198749BC00A46ACC /* lua_cocos2dx_deprecated.h in Headers */,
F4FE0D6C19ECD02400B8B12B /* LuaEventNode.h in Headers */,
@ -922,6 +931,7 @@
15EFA62B198B3220000C57D3 /* LuaOpengl.h in Headers */,
15415AD419A71A53004F1E71 /* timeout.h in Headers */,
15EFA62C198B3220000C57D3 /* lua_cocos2dx_deprecated.h in Headers */,
15B5754C1A6E9AF300041C20 /* lua-coco-studio-conversions.h in Headers */,
155C7E2919A71CE800F08B25 /* lua_cocos2dx_ui_manual.hpp in Headers */,
15EFA62D198B3220000C57D3 /* lua_cocos2dx_experimental_manual.hpp in Headers */,
F4FE0D6D19ECD02400B8B12B /* LuaEventNode.h in Headers */,
@ -1060,6 +1070,7 @@
155C7E1E19A71CC700F08B25 /* LuaSkeletonAnimation.cpp in Sources */,
15415AB519A71A53004F1E71 /* io.c in Sources */,
15C1C2CE1987498B00A46ACC /* LuaOpengl.cpp in Sources */,
15B575491A6E9AF300041C20 /* lua-coco-studio-conversions.cpp in Sources */,
566F015F19B5EB0F00FCA620 /* CustomGUIReader.cpp in Sources */,
15415AC119A71A53004F1E71 /* options.c in Sources */,
150906F019D556C5002C4D97 /* lua_cocos2dx_audioengine_auto.cpp in Sources */,
@ -1138,6 +1149,7 @@
155C7E1F19A71CC800F08B25 /* LuaSkeletonAnimation.cpp in Sources */,
15415ACA19A71A53004F1E71 /* serial.c in Sources */,
155C7DEA19A71BDA00F08B25 /* lua_cocos2dx_3d_auto.cpp in Sources */,
15B5754A1A6E9AF300041C20 /* lua-coco-studio-conversions.cpp in Sources */,
566F016019B5EB0F00FCA620 /* CustomGUIReader.cpp in Sources */,
155C7DF119A71C2300F08B25 /* lua_cocos2dx_studio_auto.cpp in Sources */,
3E2BDB0519C5E5FE0055CDCD /* lua_cocos2dx_audioengine_auto.cpp in Sources */,

View File

@ -66,6 +66,7 @@
<ClCompile Include="..\manual\cocosbuilder\lua_cocos2dx_cocosbuilder_manual.cpp" />
<ClCompile Include="..\manual\cocosdenshion\lua_cocos2dx_cocosdenshion_manual.cpp" />
<ClCompile Include="..\manual\cocostudio\CustomGUIReader.cpp" />
<ClCompile Include="..\manual\cocostudio\lua-coco-studio-conversions.cpp" />
<ClCompile Include="..\manual\cocostudio\lua_cocos2dx_coco_studio_manual.cpp" />
<ClCompile Include="..\manual\cocostudio\lua_cocos2dx_csloader_manual.cpp" />
<ClCompile Include="..\manual\extension\lua_cocos2dx_extension_manual.cpp" />
@ -138,6 +139,7 @@
<ClInclude Include="..\manual\cocosbuilder\lua_cocos2dx_cocosbuilder_manual.h" />
<ClInclude Include="..\manual\cocosdenshion\lua_cocos2dx_cocosdenshion_manual.h" />
<ClInclude Include="..\manual\cocostudio\CustomGUIReader.h" />
<ClInclude Include="..\manual\cocostudio\lua-coco-studio-conversions.h" />
<ClInclude Include="..\manual\cocostudio\lua_cocos2dx_coco_studio_manual.hpp" />
<ClInclude Include="..\manual\cocostudio\lua_cocos2dx_csloader_manual.hpp" />
<ClInclude Include="..\manual\extension\lua_cocos2dx_extension_manual.h" />

View File

@ -282,6 +282,9 @@
<ClCompile Include="..\manual\cocostudio\lua_cocos2dx_csloader_manual.cpp">
<Filter>manual\cocostudio</Filter>
</ClCompile>
<ClCompile Include="..\manual\cocostudio\lua-coco-studio-conversions.cpp">
<Filter>manual\cocostudio</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\auto\lua_cocos2dx_auto.hpp">
@ -494,6 +497,9 @@
<ClInclude Include="..\manual\cocostudio\lua_cocos2dx_csloader_manual.hpp">
<Filter>manual\cocostudio</Filter>
</ClInclude>
<ClInclude Include="..\manual\cocostudio\lua-coco-studio-conversions.h">
<Filter>manual\cocostudio</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\script\CCBReaderLoad.lua">

View File

@ -382,3 +382,8 @@ function __onParseConfig(configType,jasonStr)
ccs.TriggerMng.getInstance():parse(jasonStr)
end
end
function ccs.AnimationInfo(_name, _startIndex, _endIndex)
assert(nil ~= _name and type(_name) == "string" and _startIndex ~= nil and type(_startIndex) == "number" and _endIndex ~= nil and type(_endIndex) == "number", "ccs.AnimationInfo() - invalid input parameters")
return { name = _name, startIndex = _startIndex, endIndex = _endIndex}
end

View File

@ -7,3 +7,9 @@ ccs.MovementEventType = {
complete = 1,
loopComplete = 2,
}
ccs.InnerActionType = {
LoopAction = 0,
NoLoopAction = 1,
SingleFrame = 2,
}

View File

@ -16,7 +16,7 @@ android_flags = -D_SIZE_T_DEFINED_
clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include
clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__
cocos_headers = -I%(cocosdir)s/external -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android
cocos_headers = -I%(cocosdir)s/external -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android -I%(cocosdir)s/external/lua/luajit/include -I%(cocosdir)s/external/lua/tolua -I%(cocosdir)s/cocos/scripting/lua-bindings/manual
cocos_flags = -DANDROID
@ -26,7 +26,7 @@ cxxgenerator_headers =
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
# what headers to parse
headers = %(cocosdir)s/cocos/editor-support/cocostudio/CocoStudio.h
headers = %(cocosdir)s/cocos/editor-support/cocostudio/CocoStudio.h %(cocosdir)s/cocos/scripting/lua-bindings/manual/cocostudio/lua-coco-studio-conversions.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
@ -52,7 +52,8 @@ skip = *::[^visit$ copyWith.* onEnter.* onExit.* ^description$ getObjectType .*
ActionNode::[initWithDictionary],
ActionObject::[initWithDictionary initWithBinary],
BaseData::[copy subtract],
ActionTimelineCache::[getInstance loadActionTimelineFromXML]
ActionTimelineCache::[getInstance loadActionTimelineFromXML],
ActionTimeline::[setFrameEventCallFunc]
rename_functions = ActionManagerEx::[shareManager=getInstance purgeActionManager=destroyInstance],
SceneReader::[purgeSceneReader=destroyInstance]