文章 2023-05-25 来自:开发者社区

Lua笔记协程

fun = function() print(123) end print("**************携程的创建****************") -- (1)coroutine.create() -- (2)coroutine.wrap() co = coroutine.create( fun ) co2= coroutine.wrap( fun ) print(co2) pri...

文章 2023-05-25 来自:开发者社区

Lua笔记表实现class

-- 表内定义成员变量 Student = { age = 1, sex = true, Up = function () print(Student.age) print("Growing up") end, Learn = function() print("好好学习") end } --表外定...

文章 2017-11-27 来自:开发者社区

lua面向对象编程 《lua程序设计》 16章 笔记

Lua中的table就是一种对象,即它拥有状态、拥有独立于其值的标识(self)、table与对象一样具有独立于创建者和创建地的征集周期 什么叫对象拥有独立的生命周期? Account = {balance = 0} function Account.withdraw(v) Account.balance = Acount.balance-v end --则可进行如下调用 Ac...

文章 2017-11-26 来自:开发者社区

用户自定义类型《lua程序设计》 28章 笔记

本实例实现一种很简单的类型------布尔数组。C语言可以实现将每个布尔值存储在一个bit中,从而减少内存用量。 必须的一些宏   Code Snippet #defineBITS_PER_WORD (CHAR_BIT * sizeof(unsignedint))  //bit #defineI_WORD(i) ((unsignedint...

文章 2017-11-16 来自:开发者社区

LUA 运算笔记

文章目录[点击展开](?)[+] 循环 lua的for循环 until循环 Lua的table 循环 比如要实现这样的一个For for(int i=10;i>1;i—) {     print(i) } lua的for循环 转换成LUA for i=10,1,-1 do     print(i) end 在循环里我们常用的 –i ...

文章 2016-05-09 来自:开发者社区

Lua 笔记--元表与元方法

        可以通过元表来修改一个值的行为,使其在面对一个非预定义的操作时执行一个指定的操作。当Lua试图将两个table相加时,它会先检查两者之一是否有元表,然后检查该原表中是否有一个叫__add的字段。         Lua在创建新的table时不会创建元表,可以使用s...

文章 2016-05-09 来自:开发者社区

Lua 笔记--数学库

一、数学库 --获取系统时间 print(os.time()) --调用math.sin函数 print(math.sin(30)) --[[将角度转换成弧度 math.deg(x) --将弧度转换成角度 math.rad(x) ]] --[[指数函数、对数函数 math.exp(x) math.log(x) ]] --取整函数 local n = 3.14 prin...

文章 2016-05-09 来自:开发者社区

Lua 笔记--串行化、require和模板

--串行化: function serialize(o) if type(o) == "number" then io.write(o) elseif type(o) == "string" then io.write(string.format("%q", o)) elseif type...

文章 2016-05-09 来自:开发者社区

Lua 笔记--数据结构

a = {}    --新建一个数组 for i=1, 1000 do     a[i] = 0 end         在Lua中,有两种方式来表示矩阵。第一种是使用一...

文章 2016-05-09 来自:开发者社区

Lua 笔记--编译、执行、错误与协同程序

        一般dofile 可以这样来定义: function dofile(filename)     local f = assert(loadfile(filename))     return f() end 注意,...

本页面内关键词为智能算法引擎基于机器学习所生成,如有任何问题,可在页面下方点击"联系我们"与我们沟通。

开发与运维

集结各类场景实战经验,助你开发运维畅行无忧

+关注