issue #2868:Add manual lua binding files

This commit is contained in:
samuele3 2013-11-07 23:22:11 +08:00
parent c055b1a3d6
commit 16d572c04f
6 changed files with 188 additions and 16 deletions

View File

@ -1 +1 @@
30ca6c02884f9bc20405b3e657b444c0153bead7
f23edaa553632b07289418f9ccfae1f4f5bc1a3c

View File

@ -55,6 +55,7 @@ extern "C" {
#include "lua_cocos2dx_deprecated.h"
#include "lua_xml_http_request.h"
#include "lua_cocos2dx_studio_auto.hpp"
#include "lua_cocos2dx_coco_studio_manual.hpp"
namespace {
int lua_print(lua_State * luastate)
@ -140,6 +141,7 @@ bool LuaStack::init(void)
register_all_cocos2dx_manual(_state);
register_all_cocos2dx_extension_manual(_state);
register_all_cocos2dx_manual_deprecated(_state);
register_all_cocos2dx_coco_studio_manual(_state);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
LuaObjcBridge::luaopen_luaoc(_state);
#endif

View File

@ -101,6 +101,9 @@ public:
ASSETSMANAGER_PROGRESS,
ASSETSMANAGER_SUCCESS,
ASSETSMANAGER_ERROR,
EVENT_LISTENER,
EVENT_TOUCH_LISTENER,
};
typedef int Handler;

View File

@ -0,0 +1,156 @@
#include "lua_cocos2dx_coco_studio_manual.hpp"
#ifdef __cplusplus
extern "C" {
#endif
#include "tolua_fix.h"
#ifdef __cplusplus
}
#endif
#include "cocos2d.h"
#include "LuaBasicConversions.h"
#include "LuaScriptHandlerMgr.h"
#include "CCLuaValue.h"
#include "CocosGUI.h"
using namespace gui;
class LuaCocoStudioEventListener:public Object
{
public:
LuaCocoStudioEventListener();
virtual ~LuaCocoStudioEventListener();
virtual void setObjToLua(Object* obj);
static LuaCocoStudioEventListener* create();
virtual void eventCallbackFunc(Object* sender,int eventType)
{
if (nullptr == sender)
return;
int handler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, ScriptHandlerMgr::HandlerType::EVENT_LISTENER);
if (0 != handler)
{
//call lua funtion
}
}
private:
Object* _objToLua;
};
LuaCocoStudioEventListener::LuaCocoStudioEventListener():_objToLua(nullptr)
{
}
LuaCocoStudioEventListener::~LuaCocoStudioEventListener()
{
if (nullptr != _objToLua)
_objToLua->release();
}
LuaCocoStudioEventListener* LuaCocoStudioEventListener::create()
{
LuaCocoStudioEventListener* listener = new LuaCocoStudioEventListener();
if (nullptr == listener)
return nullptr;
listener->autorelease();
return listener;
}
void LuaCocoStudioEventListener::setObjToLua(Object* obj)
{
if (nullptr != _objToLua)
_objToLua->release();
_objToLua = obj;
_objToLua->retain();
}
static int lua_cocos2dx_UICheckBox_addEventListener(lua_State* L)
{
if (NULL == L)
return 0;
int argc = 0;
UICheckBox* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(L,1,"UICheckBox",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<UICheckBox*>(tolua_tousertype(L,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(L,"invalid 'self' in function 'lua_cocos2dx_UICheckBox_addEventListener'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(L) - 1;
if (2 == argc)
{
#if COCOS2D_DEBUG >= 1
if (!toluafix_isfunction(L,2,"LUA_FUNCTION",0,&tolua_err) ||
!tolua_isusertype(L, 3, "Object", 0, &tolua_err) )
{
goto tolua_lerror;
}
#endif
LuaCocoStudioEventListener* listern = LuaCocoStudioEventListener::create();
if (nullptr == listern)
{
tolua_error(L,"LuaCocoStudioEventListener create fail\n", NULL);
return 0;
}
LUA_FUNCTION handler = ( toluafix_ref_function(L,2,0));
Object* obj = static_cast<Object*>(tolua_tousertype(L, 3, nullptr));
listern->setObjToLua(obj);
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)listern, handler, ScriptHandlerMgr::HandlerType::EVENT_LISTENER);
self->addEventListener(listern, checkboxselectedeventselector(LuaCocoStudioEventListener::eventCallbackFunc));
return 0;
}
CCLOG("'addEventListener' function of UICheckBox has wrong number of arguments: %d, was expecting %d\n", argc, 2);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(L,"#ferror in function 'addEventListener'.",&tolua_err);
return 0;
#endif
}
static void extendUICheckBox(lua_State* L)
{
lua_pushstring(L, "UICheckBox");
lua_rawget(L, LUA_REGISTRYINDEX);
if (lua_istable(L,-1))
{
tolua_function(L, "addEventListener", lua_cocos2dx_UICheckBox_addEventListener);
}
}
int register_all_cocos2dx_coco_studio_manual(lua_State* L)
{
if (nullptr == L)
return 0;
extendUICheckBox(L);
return 0;
}

View File

@ -0,0 +1,14 @@
#ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_COCO_STUDIO_MANUAL_H
#define COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_COCO_STUDIO_MANUAL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "tolua++.h"
#ifdef __cplusplus
}
#endif
TOLUA_API int register_all_cocos2dx_coco_studio_manual(lua_State* L);
#endif // #ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_COCO_STUDIO_MANUAL_H

View File

@ -1496,6 +1496,13 @@ static int lua_cocos2dx_AssetsManager_setDelegate(lua_State* L)
if (2 == argc)
{
#if COCOS2D_DEBUG >= 1
if (!toluafix_isfunction(L, 2, "LUA_FUNCTION", 0, &tolua_err) ||
!tolua_isnumber(L, 3, 0, &tolua_err) )
{
goto tolua_lerror;
}
#endif
LuaAssetsManagerDelegateProtocol* delegate = dynamic_cast<LuaAssetsManagerDelegateProtocol*>( self->getDelegate());
if (nullptr == delegate)
{
@ -1508,21 +1515,11 @@ static int lua_cocos2dx_AssetsManager_setDelegate(lua_State* L)
delegate->release();
}
if (2 == argc)
{
#if COCOS2D_DEBUG >= 1
if (!toluafix_isfunction(L, 2, "LUA_FUNCTION", 0, &tolua_err) ||
!tolua_isnumber(L, 3, 0, &tolua_err) )
{
goto tolua_lerror;
}
#endif
LUA_FUNCTION handler = toluafix_ref_function(L, 2, 0);
ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType) ((int)tolua_tonumber(L,3,0) + (int)ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS);
LUA_FUNCTION handler = toluafix_ref_function(L, 2, 0);
ScriptHandlerMgr::HandlerType handlerType = (ScriptHandlerMgr::HandlerType) ((int)tolua_tonumber(L,3,0) + (int)ScriptHandlerMgr::HandlerType::ASSETSMANAGER_PROGRESS);
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)delegate, handler, handlerType);
return 0;
}
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)delegate, handler, handlerType);
return 0;
}
CCLOG("'setDelegate' function of AssetsManager has wrong number of arguments: %d, was expecting %d\n", argc, 2);