Forums » Lua Binding » Call LUA local function from Cocos2D-x :) »
| YuLei Liao | Call LUA local function from Cocos2D-x :) | ||
|---|---|---|---|
|
Added by YuLei Liao over 1 year ago
Example code:
function tick(dt)
....
end
cocos2d.CCScheduler:sharedScheduler():scheduleScriptFunc("tick", 0.01, false)
In above code, has one problem: tick is GLOBAL FUNCTION. Q: How to call LUA local function from Cocos2D-X ? |
||
| YuLei Liao | RE: How to call LUA local function from Cocos2D-X? | ||
|
Added by YuLei Liao over 1 year ago
Ok, i fixed all problem. I changed many cocos2d-x source files. Call lua local function from c++ it's ready. example code:
local function tick(dt)
....
end
cocos2d.CCScheduler:sharedScheduler():scheduleScriptFunc("tick", 0.01, false)
-----
local function btnTouchMove(e)
....
end
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHBEGAN, btnTouchBegin)
|
||
| YuLei Liao | RE: How to call LUA local function from Cocos2D-X? | ||
|
Added by YuLei Liao over 1 year ago
All changes based cocos2d-1.0.1-x-0.9.1. git repo: https://github.com/dualface/cocos2d-x/tree/cocos2d-1.0.1-x-0.9.1-lua-fix |
||
| alex cheng | RE: Call LUA local function from Cocos2D-x :) | ||
|
Added by alex cheng over 1 year ago
I use another way to implement it, it needn't modify any cocos2d-x codes. |
||
| YuLei Liao | RE: Call LUA local function from Cocos2D-x :) | ||
|
Added by YuLei Liao over 1 year ago
alex cheng wrote:
Very good! |
||
| alex cheng | RE: Call LUA local function from Cocos2D-x :) | ||
|
Added by alex cheng over 1 year ago
maybe. BTW:Do we really care about what this performance? |
||
| Eric Tbone | RE: Call LUA local function from Cocos2D-x :) | ||
|
Added by Eric Tbone over 1 year ago
Why were callbacks done by variable name anyway? Functions are first class values in Lua; you should be able to pass a function, not a string, and have that function called. The scope of the variable where that function value is stored in the users code should be irrelevant. You should be able to use anonymous functions if you want, too:
I can't see YuLei Liao's code (link is busted), but I imagine he just added support for storing function references. If I add this to my copy of coco2d-x, how would I go about submitting it back to the repository? I've never contributed to an open source project before, but I know Lua quite well and will probably be working on this binding for my own use anyway. |
||
| qi luo | RE: Call LUA local function from Cocos2D-x :) | ||
|
Added by qi luo over 1 year ago
this is my way,it needn't modify any cocos2d-x codes. _ just replace the content of hello.lua in project HelloLua. Have a try! |
(1-7/7)