-- -- --*****************************************************************************
-- -- string.dump (function [, strip]) --字符串转化二进制函数
local function add(a,b)
print("大家好")
end
local fun = string.dump(add)
print(fun) -- 字节码
local fun1 = load(fun)
fun1()
-- -- --*****************************************************************************
-- 下面的表列出了Lua支持的所有字符类:
-- 单个字符(除 ^$()%.[]*+-? 外): 与该字符自身配对
-- .(点): 与任何字符配对
-- %a: 与任何字母配对
-- %c: 与任何控制符配对(例如\n)
-- %d: 与任何数字配对
-- %l: 与任何小写字母配对
-- %p: 与任何标点(punctuation)配对
-- %s: 与空白字符配对
-- %u: 与任何大写字母配对
-- %w: 与任何字母/数字配对
-- %x: 与任何十六进制数配对
-- %z: 与任何代表0的字符配对
-- %x(此处x是非字母非数字字符): 与字符x配对. 主要用来处理表达式中有功能的字符(^$()%.[]*+-?)的配对问题, 例如%%与%配对
-- [数个字符类]: 与任何[]中包含的字符类配对. 例如[%w_]与任何字母/数字, 或下划线符号(_)配对
-- [^数个字符类]: 与任何不包含在[]中的字符类配对. 例如[^%s]与任何非空白字符配对
-- string.find (s, pattern [, init [, bool]])
--[[
s = string
pattern = 要匹配的内容
init = i 开始搜索的位置
bool 布尔 特殊符号的匹配
-- utf8(1-4字节)/utf16/ansi/gb18030(2-字节)
-- Unicode 是同一字符集
]]--
-- 练习2 搜索传入的武器是否在字符串str里,如果在
local str = "木剑|屠龙|麻花|裁决|钩子"
local function add(characterString,searchFor)
local start,complete = string.find(characterString,searchFor)
if start then
print("是的没错,"..searchFor.."在我手里,有本事你来抢啊?!".."所在位置:"..start.."-"..complete)
else
print("休要血口喷人"..searchFor.."根本不在我手里")
end
return start,complete
end
local ppd,ppd2 = add(str,"AK")
print(ppd,ppd2)
-- 练习2 传入起始搜索位置,并搜索传入的武器是否在字符串str里,如果在
local str = "木剑|屠龙|麻花|裁决|钩子"
local function add(characterString,searchFor,startPosition)
local start,complete = string.find(characterString,searchFor,startPosition)
if start then
print("是的没错,"..searchFor.."在我手里,有本事你来抢啊?!".."所在位置:"..start.."-"..complete)
else
print("休要血口喷人"..searchFor.."根本不在我手里")
end
return start,complete
end
local ppd,ppd2 = add(str,"麻花",1)
print(ppd,ppd2)