cocos2d-x lua 一些语法

cocos2d-x lua 加载json控件并获取控件

gold = GUIReader:shareReader():widgetFromJsonFile("**.json")

goldTxt = tolua.cast(gold:getWidgetByName("txt"),"Label")

获取到“text”的控件并转换成Laber标签赋值给goldTxt,goldTxt就带有Label的属性,可以调用Label的方法

在cocos2d-x lua项目中:

比如:hintText.lua文件中的代码如下:

module( "hintText", package.seeall )

text = { "a", "b" }

function demo ()
  
end

则表示包里面的方法和变量都给了hintText,在别的包引入该包时( 引入方法:require( "hintText" ) ),则直接hintText.text[ 1 ], hintText.demo()调用

( 刚在项目中接触lua,如果有什么不对的地方,欢迎大家留言指正! 谢谢 )

在lua中打印堆栈:

print( debug.traceback() )

lua暂停程序执行(相当于C++ System("pause")

os.execute("pause")
原文地址:https://www.cnblogs.com/Colored-Mr/p/4685888.html