lua

深入探究Lua的GC算法(下)-《Lua设计与实现》

a 夏天 提交于 2021-02-04 04:27:50
紧接着上一篇文章 zblade:深入探究Lua的GC算法(上)-《Lua设计与实现》 这篇文章让我们收尾GC的具体后续操作。转载请标明出处: http://www.cnblogs.com/zblade/ 3、GC的扫描阶段 GCSpropagate 只要处于这个阶段,就会分2种情况执行,一个是propagatemark,一个是atomic,让我们分别看其实现过程。 首先看处于灰色链表中一直都有对象的情况,在这步操作当中,是可以分步操作的,整个GC的分步操作,就是在这一步操作中,在每次扫描后,都会返回本次扫描标记的对象的大小之和,再下一个分步执行的时候再继续执行,而一旦进入atomic函数中,就需要一次性的执行,不能再分步执行了。 来看propagatemark函数是如何实现的: 对于table,如果该表是weak表,则退回到灰色状态,否则遍历表的数组和散列表部分进行标记,详见traversetable函数; 对于func,traverseclosure主要对func中的upval进行标记; 对于thread, 则将其移植到grayagain中,放在atomic中进行处理; 对于proto,对其中的字符串、upvalue、局部变量等进行遍历标记; 注意,这儿没有处理string\udata类型数据,这是放在其他部分进行的,不需要进行相关的标记; 4、GC 扫描阶段的barrier操作

redis执行lua脚本实战

被刻印的时光 ゝ 提交于 2021-02-04 04:22:29
eval调用传递参数 [root@base task]# redis-cli 127.0.0.1:6379> eval "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second 1) "key1" 2) "key2" 3) "first" 4) "second" 127.0.0.1:6379> 其中2为参数的redis键key的个数,key1,key2为redis键key,first,second为键名的附加参数。在lua脚本中通过KEYS和ARGV数组对脚本执行指定的参数进行访问。 调用redis的set命令(方式一) 127.0.0.1:6379> eval "return redis.call('set','foo','bar')" 0 OK 127.0.0.1:6379> get foo "bar" 127.0.0.1:6379> 调用redis的set命令(方式二) 127.0.0.1:6379> eval "return redis.call('set',KEYS[1],'bar')" 1 foo OK 127.0.0.1:6379> get foo "bar" 127.0.0.1:6379> 需要注意的是,上面这段脚本的确实现了将键 foo 的值设为 bar 的目的,但是,它违反了 EVAL

深入Lua:Table的实现

£可爱£侵袭症+ 提交于 2021-02-04 04:04:54
Table的结构 Lua和其他语言最不同的地方在于,它只有一个叫表的数据结构:这是一个数组和哈希表的混合体。神奇的地方在于只通过表,就可以实现模块,元表,环境,甚至面向对象等功能。这让我们很好奇它内部的结构到底是怎么样的。 它的结构定义在 lobject.h 中,是这样的: typedef struct Table { // 这是一个宏,为GCObject共用部分,展开后就是: // GCObject *next; lu_byte tt; lu_byte marked // 所有的GC对象都以这个开始 CommonHeader; // 和快速判断元方法有关,这里可以先略过 lu_byte flags; // 哈希部分的长度对数:1 << lsizenode 才能得到实际的size lu_byte lsizenode; // 数组部分的长度 unsigned int sizearray; // 数组部分,为TValue组成的数组 TValue * array ; // 哈希部分,为Node组成的数组,见下面Node的说明 Node *node; // lastfree指明空闲槽位 Node *lastfree; // 元表:每个Table对象都可以有独立的元表,当然默认为NULL struct Table * metatable ; // GC相关的链表,这里先略过 GCObject

Redis 实战 —— 14. Redis 的 Lua 脚本编程

百般思念 提交于 2021-02-04 02:15:34
简介 Redis 从 2.6 版本开始引入使用 Lua 编程语言进行的服务器端脚本编程功能,这个功能可以让用户直接在 Redis 内部执行各种操作,从而达到简化代码并提高性能的作用。 P248 在不编写 C 代码的情况下添加新功能 P248 通过使用 Lua 对 Redis 进行脚本编程,我们可以避免一些减慢开发速度或者导致性能下降对常见陷阱。 P248 将 Lua 脚本载入 Redis P249 SCRIPT LOAD 命令可以将脚本载入 Redis ,这个命令接受一个字符串格式的 Lua 脚本为参数,它会把脚本存储起来等待之后使用,然后返回被存储脚本的 SHA1 校验和 EVALSHA 命令可以调用之前存储的脚本,这个命令接收脚本的 SHA1 校验和以及脚本所需的全部参数 EVAL 命令可以直接执行指定的脚本,这个命令接收脚本字符串以及脚本所需的全部参数。这个命令除了会执行脚本之外,还会将被执行的脚本缓存到 Redis 服务器里面 由于 Lua 的数据传入和传出限制, Lua 与 Redis 需要进行相互转换。因为脚本在返回各种不同类型的数据时可能会产生含糊不清的结果,所以我们应该尽量显式的返回字符串。 P250 我们可以在 官方文档 中找到 Redis 和 Lua 不同类型之间的转换表: Redis 类型转换至 Lua 类型 Redis Lua integer reply

Redis 有什么优势?

微笑、不失礼 提交于 2021-02-01 09:06:15
一、性能高,速度快 Redis 命令执行速度非常快,官方给出的读写性能可以达到 10W / 秒。为什么会如此之快呢?有以下几个因素: 1.数据存储在内存中,直接与内存连接; 2.有相对底层的 C 语言实现,离操作系统更近; 3.实现源码很精湛,仅仅几万行代码,简单稳定; 4.使用了单线程模型,无多线程竞争、锁等问题。 二、丰富的数据结构 Redis 与其他的内存数据库不同的是,Redis 拥有丰富的数据类型,如字符串、哈希、列表、集合、有序集合等。正是因为 Redis 丰富的数据类型,所以它能应用的场景非常多。 三、丰富的特性 除了支持丰富的数据结构外,还支持以下高级功能: 1.支持键过期功能,可以用来实现定时缓存; 2.支持 发布 / 订阅 功能,可以用来实现消息队列; 3.支持事务功能,可以保证多条命令的事务性; 4.支持供管道功能,能够批量处理命令; 5.支持 Lua 脚本功能; 6.支持集群分片和数据复制功能; 7.支持内存数据持久化硬盘功能 四、丰富的客户端 官方索引:http://www.redis.cn/clients.html 从官方给出的客户端列表可以看出各种各样的语言都能接入到 Redis,接入包括了所有的主流开发语言。 目前使用 Redis 的公司非常多,国内外都有很多重量级的公司在用。所以,现在学习 Redis 是大势所趋,学好 Redis

NumberValue is not changing in Roblox Workspace

醉酒当歌 提交于 2021-01-29 19:01:27
问题 I made this script for a bomb that explodes if a value isn't ten, but the value does not change in workspace and even if I change it manually to 10 the bomb still explodes anyways. The bomb has a button to add one to the value and a button to enter, which is supposed to cause it to either explode or not explode but it always explodes. this is the script for the enter button: local Beans = workspace.BigBoomRoom.bomb.button3.Beans.Value function AwMan() end function Creeper() local explosion =

Roblox - attempt to index nil with 'leaderstats'

你。 提交于 2021-01-29 18:22:01
问题 Can someone tell me how can I fix this error that shows up when I run my script? Thanks line 4: Workspace.Slide1.PointsPart.Script:4: attempt to index nil with 'leaderstats' script.Parent.Touched:Connect(function(hit) local player = hit.Parent:FindFirstChild("Humanoid") local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr.leaderstats.Points.Value >= 0 then wait() script.Disabled = true script.Parent.Transparency = 1 script.Parent.CanCollide = false plr.leaderstats.Points.Value =

Logitech Lua Sleep Behavior

▼魔方 西西 提交于 2021-01-29 17:14:39
问题 Since Egor always help, this is intended to show him the problem, but if you know how to solve, please help too! https://youtu.be/J2vRfnUplio <<< this is how the script should work. (look at the descripition for more info) https://youtu.be/HH_MmfXUdl8 <<< This is how it doing now, at windows newer versions. Having problems with Sleep() func on MouseMoveRelative on LUA ^^ This is the last question that shows the problem and you helped me there GHUB has the same version on both, so isnt GHUB

How to fix NPCs not spawning

元气小坏坏 提交于 2021-01-29 15:27:23
问题 I coded out some functions in a ModuleScript to be executed by another script. Here is the code local module = {} wavepause = game.ReplicatedStorage.Values.WavePauseLength.Value trollanoid = game.ReplicatedStorage.Trollanoid spawnpoints = workspace.Test1.Spawns:GetChildren() function trollanoidsummon() local chosenspawn = math.random(#spawnpoints) local clone = trollanoid:Clone().Parent == workspace.Zombies clone.HumanoidRootPart.CFrame = chosenspawn.CFrame end module.Wave1 = function()

How i can merge this 2 different Lua script in ONE? it is for my logitech mouse and i am not able to combine this 2 toggle script

筅森魡賤 提交于 2021-01-29 09:10:31
问题 Hello I want to combine this 2 toggle script. It is for a game. I am not good at this script and I need help for merge scripts. I would like when I press G7 button the mouse pull down of x pixel when I press left button of mouse when I press g8 button the mouse pull down of y pixel when I press left mouse button. Script1 function OnEvent(event, arg) OutputLogMessage("event = %s, arg = %d\n", event, arg) if (event == "PROFILE_ACTIVATED") then EnablePrimaryMouseButtonEvents(true) elseif event =