Cocos2d-x 2.20 and later versions do not have to create a template, the method to create instead of Python to create, the method is as follows:
Python create_project.py-project HelloWorld-package com. Panda. Game-language cpp
To create a lua project, change the ending cpp to lua.
Then open the created sln project file and run it directly to find that it is a finished product. There are pictures, sound effects, and animations =
Examples/K/c/C0tG + rdC0wcu9xbG + examples/examples + CjwvcD4KPHA + PGJyPgo8L3A + examples/examples + bxloyw1%0g "PandaWu"
HelloTable = {name = "Panda", IQ = 129}
Function helloAdd (num1, num2, num3)
Return (num1 + num2 + num3)
End
Initialize, open the lua file, and set the stack pointer:
Lua_State * pL = lua_open ();
Luaopen_base (pL );
Luaopen_math (pL );
Luaopen_string (pL );
Int err = luaL_dofile (pL, "HelloLua. lua ");
CCLOG ("open: % d", err );
Lua_settop (pL, 0 );
Take the myName variable:
Lua_getglobal (pL, "myName ");
Int isstr = lua_isstring (pL, 1 );
CCLOG ("isstr = % d", isstr );
If (isstr! = 0)
{
Const char * str = lua_tostring (pL, 1 );
CCLOG ("get string % s", str );
}
Name and IQ In the table:
Lua_getglobal (pL, "helloTable ");
Lua_pushstring (pL, "name ");
Lua_gettable (pL,-2 );
Const char * name = lua_tostring (pL,-1 );
CCLOG ("% s", name );
Lua_getglobal (pL, "helloTable"); // you have to write this sentence.
Lua_pushstring (pL, "IQ"); // or pushstring
Lua_gettable (pL,-2 );
Int IQ = lua_tonumber (pL,-1 );
CCLOG ("% d", IQ );
Call helloAdd in lua:
Lua_getglobal (pL, "helloAdd ");
Lua_pushnumber (pL, 10 );
Lua_pushnumber (pL, 5 );
Lua_pushnumber (pL, 3 );
Lua_call (pL, 3, 1); // number of parameters and number of returned values
Int result = lua_tonumber (pL,-1 );
CCLOG ("result = % d", result );
Last: lua_close (pL );