lua入门学习笔记

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值