Created
February 28, 2012 15:25
-
-
Save xkyii/1933122 to your computer and use it in GitHub Desktop.
My Lua Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- func to be hooked | |
function test(a,b) | |
print('\norg test'); | |
print('a='..a..' b='..b) | |
return a,b; | |
end | |
-- store original func | |
org_test = test; | |
-- set to a hook_func | |
test = function(...) | |
print('\nhook test'); | |
print(...) | |
return org_test(...); | |
end | |
-- test | |
print(test(1,2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--https://github.com/harningt/luajson | |
require("json") | |
--取得文件内容(可读取utf-8文件) | |
local io = require("io") | |
local f = io.open("data.txt") | |
local data = f:read('*a') | |
print(data) | |
--print(type(data)) | |
f:close() | |
local dec = json.decode(data) | |
print(dec) | |
print(dec["200"].name) | |
print((tonumber(dec["200"]["1"]))) | |
print((dec["210"]["1"])) | |
-- data.txt | |
local data_txt = | |
[[ | |
{ | |
"200":{ | |
"1":"11", | |
"2":"x22", | |
"name":"tom" | |
}, | |
"210":{ | |
"1":"y11", | |
"2":"y22" | |
} | |
} | |
]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--https://github.com/harningt/luajson | |
require("json") | |
--取得文件内容(可读取utf-8文件) | |
local io = require("io") | |
local f = io.open("data.txt") | |
local data = f:read('*a') | |
print(data) | |
--print(data[1].p) | |
--print(type(data)) | |
f:close() | |
local dec = json.decode(data) | |
print(dec) | |
print(dec[1].x) | |
print(dec[1].t) | |
print(dec[2].x) | |
print(dec[2].t) | |
-- data.txt | |
local data_txt = | |
[[ | |
[ | |
{x:111,y:222,z:3333}, | |
{x:222,y:333,z:4444,t:"兰州烧饼"} | |
] | |
]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('luaxml') | |
print('test begin') | |
local xfile = xml.load('test_utf8.xml') | |
local settings = xfile:find('Settings') | |
if(settings~=nil) then | |
print('Settings is exist') | |
--print(settings) | |
local node273 = settings:find('1033') | |
--local node1016 = node273:find('1016') | |
print(node273) | |
--print(node1016['name']) | |
end | |
-- create a new XML object and set its tag to "root" | |
--local x = xml.new("root") | |
-- append a new subordinate XML object, set its tag to "child", and its content to 123 | |
--x:append("child")[1] = 123 | |
--print(x) | |
--<Settings> | |
-- <273> | |
-- <1016 name="xxxx">ASmailPath.xml</1016> | |
-- </273> | |
--</Settings> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--方法1 | |
--在一个死循环中设置一个跳出条件,但是这样的做法会占用大量CPU资源,强烈不推荐使用哦 | |
function sleep(n) | |
local t0 = os.clock() | |
while os.clock() - t0 <= n do end | |
end | |
--方法2 | |
--调用系统的sleep函数,不消耗CPU,但是Windows系统中没有内置这个命令(如果你又安装Cygwin神马的也行)。推荐在Linux系统中使用该方法 | |
function sleep(n) | |
os.execute("sleep " .. n) | |
end | |
--方法3 | |
--虽然Windows没有内置sleep命令,但是我们可以稍微利用下ping命令的性质 | |
function sleep(n) | |
if n > 0 then os.execute("ping -n " .. tonumber(n + 1) .. " localhost > NUL") end | |
end | |
--方法4 | |
--使用socket库中select函数,可以传递0.1给n,使得休眠的时间精度达到毫秒级别。 | |
require("socket") | |
function sleep(n) | |
socket.select(nil, nil, n) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment