请教大神解释下面这个lua脚本,有几段看不懂啊
lua吧
全部回复
仅看楼主
level 3
💧后🌈 楼主
function start()
local mysql = require "luasql.mysql"
local file=io.input("./conf/realms.conf")
local str=io.read("*a")
file:close()
local t = {}
for v in string.gmatch(str,"\"([A-Za-z0-9_.]+)\"") do --看不懂
table.insert(t,v) --看不懂
end
envt = assert(mysql.mysql())
conn = assert(envt:connect(t[10],t[8],t[9],t[7],t[11])) --尤其这段看不懂
conn:execute"SET NAMES utf8"
end
realms.conf代码如下:
<LogonServer Address = "127.0.0.1" Port = "17991" Name = "Default Logon" RealmCount = "1">
<MonitorServer Address = "0.0.0.0" Port = "54082" Enable = "0">
<WorldDatabase Hostname = "127.0.0.1" Username = "root" Password = "123456" Name = "game" Port = "3306">
<Realm1 Name = "test"
Address = "10.1.1.100:60816"
Icon = "PVP"
Population = "1.0"
TimeZone = "1">
2016年03月23日 01点03分 1
level 3
大题用途我猜应该是输入一个参数到str中,取出一些参数放到表t里,你第一个和第二个看不懂的就是这作用。最后那段是使用获得的参数打开数据库,使用了mysql的库,这库不知道咋用的,你可以仔细查查
2016年03月23日 07点03分 2
刚开始学,参考
2016年03月23日 07点03分
2016年03月23日 12点03分
level 3
for v in string.gmatch(str,"\"([A-Za-z0-9_.]+)\"") do 这个是将realms.conf文本中的有双引号的字符串匹配出来,然后通过table.insert(t,v)将它一个一个存到table t中。
t = {
127.0.0.1
17991
1
0.0.0.0
54082
0
127.0.0.1
root
123456
game
3306
test
PVP
1.0
1
}
上面就是table t中存的数据了。应该是这样子。
2016年03月23日 09点03分 3
这下看懂了 ,多谢
2016年03月23日 12点03分
原来是这个意思【这个是将realms.conf文本中的有双引号的字符串匹配出来】
2016年03月23日 12点03分
1