Lua_getglobal (lua_State * L, const char * name): press the value in the global variable name into the stack.
Lua_gettable (lua_State * L, int index): press the t [k] value into the stack. Here, t refers to the value pointed to by the valid index, k is the value at the top of the stack.
Lua_isstring (lua_State * L, int index): If the value of the given index is a string or a number (the number can always be converted to a string), 1 is returned; otherwise, 0 is returned.
Lua_next (lua_State * L, int index): A key (key) pops up from the stack, and then the key-value (key value) in the table specified by the index) press the pair into the stack (specify the next pair after the key ).
Lua_pushstring (lua_State * L, const char * s): press the string whose pointer s points to at zero end to the stack.
Lua_pushnil (lua_State * L): press an nil stack.
Lua_pop (lua_State * L, int n): pops up n elements from the stack.
Lua_tolstring (lua_State * L, int index): converts the index value to the string type.
The author's IDE Xcode 5.0 + Cocos2d-x-2.2.2
What we will do below is to store all the elements in the table variable in A. lua file to the CCDictionary object in the Cocos2d-x, the content in the. lua file is as follows:
LuaTable = {age = 3, name = Reventon, sex = male, skill = {Lua, c ++, oc}, type = {type1 = master, type2 = monster }, state = {happy, angry }}
After being stored in CCDictionary, the value corresponding to the skill key and state key in the dictionary is of the CCArray type, and the value corresponding to the type key is of the CCDictionary type.
Create a Lua-based project named Reventon (Project Creation Method see: http://blog.csdn.net/u012945598/article/details/17115875)
Create a cpp file named LTData.
First, we need to introduce the header file required to access Lua, and add the following code in the LTData. h file:
LTData. cpp file code:
Next we will introduce the LTData. h header file in AppDelegate. cpp, and then add the following code to applicationDidFinishLaunching () for testing:
We export all the content in the dictionary and output it. The console result is as follows:
The content is consistent with that in the myLua. lua file: