C++ game with part lua logic, ComponentLua, lua bindings

C++ game with part lua logic, ComponentLua, lua bindings

Hi everyone! I’ve created my C++ project, I found the cocos2dx engine very flexible, convinient and powerful for making games, but I’ve stuck on this moment. I want make part of logic of my game on Lua, I want write UI and some sprites behaviour in Lua, but main part (most of components) of game I want write in C++.

I’ve found chapter Scripting/Script component in cocos2dx Programmers guide:
Example with Lua:

// create a Sprite and add a LUA component
auto player = Sprite::create("player.png" );
auto luaComponent = ComponentLua::create("player.lua" );

-- player.lua
local player = {
	onEnter = function(self)
	-- do some things in onEnter
	onExit = function(self)
	-- do some things in onExit
	update = function(self)
	-- do some things every frame
-- it is needed to return player to let c++ nodes know it
return player

I tried to do this, but I’ve got compilation error: error C2653: ComponentLua
I’m looking for scripting subdir in cocos2d/cocos/ in my project folder and did not find this. Why?
How can I properly create bindings to lua from my C++ code? May be there is some right tutorial?

No one can help me?

You need to create Lua project or import cocos2d_lua_bindings.xcodeproj .

I saw your post but was overseas.
I blogged about this a while ago
I ended up using Chaiscript rather than Lua so probably can’t help much more than pointing you to my blog.

good luck!

write lua binging yourseft

Unfortunately I have not mac for ios development. I write code in Microsoft Visual Studio 2015 Community under Windows 7 test by project on Windows and build it for android.
Therefore I added libluacocos2d to my project from cocos2d_x_3.15.1\cocos\scripting\lua-bindings\proj.win32\libluacocos2d.vcxproj rebuild my project but there is linking error:
DemoScene.obj : error LNK2019: unresolved external symbol "public: static class cocos2d::ComponentLua * __cdecl cocos2d::ComponentLua::create(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?create@ComponentLua@cocos2d@@SAPAV12@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)

It seems hard to include lua scripting to my game. Maxxx, thanks I will try this way.