"翻译" lua中的另一个角色

时间:2016-05-03 00:56:48

标签: lua hexchat

我想创建一个lua脚本来获取表的输入,然后以全宽对应的方式输出该表中的字符串,例如

input = {"Hello", " ", "World"}
print(full(table.concat(input)))

它将打印" Hello World"

我尝试使用它:

local encoding = [[ 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!゛#$%&()*+、ー。/:;〈=〉?@[\\]^_‘{|}~]]
function char(i)
   return encoding:sub(i:len(),i:len())
end
function decode(t)
   for i=1,#t do t[i]=char(t[i]) end
   return table.concat(t)
end
function returns(word, word_eol)
    print(char(word_eol[2]))
end

但这不起作用

注意:这是一个hexchat的插件,这就是为什么我将它作为print(char(word_eol[2])))

因为当你在hexchat中挂钩一个命令时,会吐出一个表,这个表是命令名,然后是

之后输入的内容。

2 个答案:

答案 0 :(得分:1)

function full(s)
   return (s:gsub('.', function(c)
      c = c:byte()
      if c == 0x20 then
         return string.char(0xE3, 0x80, 0x80)
      elseif c >= 0x21 and c <= 0x5F then
         return string.char(0xEF, 0xBC, c+0x60)
      elseif c >= 0x60 and c <= 0x7E then
         return string.char(0xEF, 0xBD, c+0x20)
      end
   end))
end

答案 1 :(得分:1)

如果(字符串)= [[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!゛#$%&()* +,ー。/:; <=>?@ []] ^ _'{|}〜]],你是&lt; re找到(字符串)的 n 字符,其中 n 是字符的长度,它始终为1。如果我理解正确,这将通过单独的字母表和匹配字符来完成工作。

local encoding = [[ 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!゛#$%&()*+、ー。/:;〈=〉?@[]^_‘{|}~]]
local decoding = [[ 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;{=}?@[]^_'{|}~]]
function char(i)
   local l = decoding:find(i,1,true)
   return encoding:sub(l,l)
end
function decode(t)
   for i=1,#t do t[i]=char(t[i]) end
   return table.concat(t)
end
function returns(word, word_eol)
    print(char(word_eol[2]))
end