helloworld:
#include "stdafx.h"
#include <iostream>
#include <string>
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#pragma comment(lib,"../Debug/lua.lib")
using namespace std;
int main()
{
lua_State *L = luaL_newstate();/* opens Lua */
luaopen_base(L); /* opens the basic library */
luaopen_table(L); /* opens the table library */
luaopen_io(L); /* opens the I/O library */
luaopen_string(L); /* opens the string lib. */
luaopen_math(L); /* opens the math lib. */
luaL_openlibs(L);
luaL_dofile(L,"test.lua");
lua_close(L);
system("pause");
return 0;
}
1. print(10..20) ----> 1020 两个点表示连接字符串操作。
2。
逻辑运算符认为false和nil是假(false),其他为真,0也是true.
and和or的运算结果不是true和false,而是和它的两个操作数相关。
a and b -- 如果a为false,则返回a,否则返回b
a or b -- 如果a为true,则返回a,否则返回b
aa=false;
bb=0;
cc=2;
print( (aa and bb) or cc) 相当于aa ?bb:cc的用法
3.chunk变量被声明的那个文件或者文本串
4.闭包的思想:
function newCounter()
local i = 0
return function() -- anonymous function
i = i + 1
return i
end
end
c1 = newCounter()
print(c1()) --> 1
print(c1()) --> 2