Problem in Understanding and Using ComponentLua

Hi,

I’ve been struggling to understand ComponentLua and to make it work, without success. I explain what I have done so far:

  1. I created a new Lua Cocos2d-x project.

  2. I created a new class HelloWorld.cpp (inheriting from Layer, as usual), and in the init() method I wrote:

    auto luaTest = ComponentLua::create(“Test.lua”);
    this -> addComponent(luaTest);

This wouldn’t compile in the first try, but it did when I added the following at the beginning of HelloWorld.cpp:

#include "CCComponentLua.h"
  1. I’ve created a new Test.lua file inside the Resources folder, with the following content:

    local Test = {
    onEnter = function(self)
    – whatever
    end

    onExit = function(self)
    – do some things in onExit
    end

    update = function(self)
    – do some things every frame
    end
    }
    return Test

When I build this, I get the following error:

[LUA ERROR] load “/var/mobile/Containers/Bundle/Application/FFEB4637-680A-435F-856B-6A9FD937B5A3/TestLua-mobile.app/Test.lua”, error: syntax error during pre-compilation.
ComponentLua::loadAndExecuteScript: [string “/var/mobile/Containers/Bundle/Application/FFE…”]:7: ‘}’ expected (to close ‘{’ at line 1) near ‘onExit’

The first and most obvious question is: why is the script failing?

However, I have other questions:

  1. Is it really necessary to add the include directive (CCComponentLua.h). I would’ve expected that cocos2d.h had added that for me in the Lua project.

  2. I moved an existing and current C++ project (actually, only copied its .h and .cpp files) into this Lua project. However, I was surprised to find lots of build errors pointing to unknown “std” (C++) declarations. I fixed these errors by including cocos2d.h in the files that failed, but I don’t understand why this is necessary for this Lua project and not for the C++ project.

Thanks in advance.
FM

UPDATE: I forgot to mention that it’s an iOS project and I’m working with Xcode 7.2.

EDIT: I posted the question on Stackoverflow: http://stackoverflow.com/questions/35011523/understanding-componentlua-in-cocos2d-x-3-9