Is that anyone who ever used setAccelerometerInterval function in lua?

I write a game in lua, I want to use Accelerometer in it. I write code like this:
@
mylayer:setAccelerometerEnabled(true)
— mylayer:setAccelerometerInterval(2)
mylayer:registerScriptAccelerateHandler(didAccelerate)
@
As you see I commented the second line code. If I removed the comment and open the second line code, there is an eror will be happened like this ‘method ’setAccelerometerInterval’ (a nil value)’. Why I can set the accelerometer interval? Is that anyone who know how to set the inverval? Thank you a lot!
If I’m not call setAccelerometerInterval function, the didAccelerate will be called at every frames, this is not what I want.

Thanks Martin Z! Finally I get the place of how to binding functions. It is at ./cocos2d_support/LuaCocos2d.cpp. At this cpp, we can see there are a list of functions binding code.

The setAccelerometerInterval method has no lua binding, that’s why it’s nil. You will have to generate the binding by yourself. Then you can use setAccelerometerInterval.

Thanks, old sport! Can you kindly to tell me how to check any function is binding or not? Of course not try to call it to check the running status is nil or not. I mean can I check them in the code of Lua engine. Thank you again!

Martin Z wrote:

The setAccelerometerInterval method has no lua binding, that’s why it’s nil. You will have to generate the binding by yourself. Then you can use setAccelerometerInterval.

In the directory cocos2d-x/tools/tolua++ are the bindings (I’m using version 3, maybe they are somwhere else in version 2). The bindings for each class are defined in the .pkg files. So if you open CCLayer.pkg you can see that setAccelerometerInterval is missing.

If you add the signature of setAccelerometerInterval to the pkg file, you can re-generate the bindings with build.sh or build.bat (on windows). You need to extract the tolua binary for your operating system first.
You can add it after the isAccelerometerEnabled binding.
@
void setAccelerometerEnabled(bool bValue);
bool isAccelerometerEnabled() const;
void setAccelerometerInterval(double interval);
@

Thank you very much! You really give me a big hand. At my last repay, I think I get the point of how to add one lua binding, but after looked at your replay, I know the right way of binding lua. Thank you again!

Martin Z wrote:

In the directory cocos2d-x/tools/tolua++ are the bindings (I’m using version 3, maybe they are somwhere else in version 2). The bindings for each class are defined in the .pkg files. So if you open CCLayer.pkg you can see that setAccelerometerInterval is missing.
>
If you add the signature of setAccelerometerInterval to the pkg file, you can re-generate the bindings with build.sh or build.bat (on windows). You need to extract the tolua binary for your operating system first.
You can add it after the isAccelerometerEnabled binding.
@
void setAccelerometerEnabled(bool bValue);
bool isAccelerometerEnabled() const;
void setAccelerometerInterval(double interval);
@