打開終端機(terminal)

step 2.
輸入指令:
sudo tmutil disablelocal
輸入密碼: 一般來說會是你的開機密碼
step 4. 重新開機
local dog = require "Dog" --引入類別
local BigDog = dog.New( "Apple" , 10 ) --創建物件
local SmallDog = dog.New( "Orange" , 4 )
BigDog:Bark()
BigDog:PrintAge()
SmallDog:Bark()
SmallDog:PrintAge()
local Object = {}
-------------------------------------------------
-- GLOBAL
-------------------------------------------------
function Object.New( name , ageInYears )-- constructor
local self =
{
name = name ,
age = ageInYears
}
-------------------------------------------------
-- PRIVATE FUNCTIONS
-------------------------------------------------
local function GetDogYears( realYears ) -- local; only visible in this module
return realYears * 7
end
-------------------------------------------------
-- PUBLIC FUNCTIONS
-------------------------------------------------
function self:Bark()
print( self.name .. " says \"woof!\"" )
end
function self:PrintAge()
print( self.name .. " is " .. GetDogYears( self.age ) .. " in dog years." )
end
return self
end
return Object
---------------------
--產生GUID
--範例:
--[[
local guid = require( "Tool.Guid")
print("guid.NewHex" , guid.NewHex())
print("guid.NewLong" , guid.NewLong())
]]--
---------------------
local M = {}
--樣本數為 2^128
function M.NewHex()
--隨機種子
local d = io.open("/dev/urandom", "r"):read(4)
local template ="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
math.randomseed(os.time() + d:byte(1) + (d:byte(2) * 256) + (d:byte(3) * 65536) + (d:byte(4) * 4294967296))
return string.upper(string.gsub(template, "x",
function (c)
local v = (c == "x") and math.random(0, 0xf) or math.random(8, 0xb)
return string.format("%x", v)
end))
end
--樣本數為 2147483647
function M.NewLong()
--隨機種子
local d = io.open("/dev/urandom", "r"):read(4)
math.randomseed(os.time() + d:byte(1) + (d:byte(2) * 256) + (d:byte(3) * 65536) + (d:byte(4) * 4294967296))
return math.random( 1 , 2147483647 )
end
return M
local a = 10
local b = 20
print("a>b" , (a>b) and true or false )
print("a<b" , (a<b) and true or false )
print("a==b" , (a==b) and true or false )
local cos = math.cos
local sin = math.sin
local pi = math.pi
local sqrt = math.sqrt
local min = math.min
local asin = math.asin
local abs = math.abs
-- Calculate distance
function Distance(from, to)
local distance = 0
local radius = 6367000
local radian = pi / 180
local deltaLatitude = sin(radian * (from.latitude - to.latitude) /2)
local deltaLongitude = sin(radian * (from.longitude - to.longitude) / 2)
local circleDistance = 2 * asin(min(1, sqrt(deltaLatitude * deltaLatitude +
cos(radian * from.latitude) * cos(radian * to.latitude) * deltaLongitude * deltaLongitude)))
distance = abs(radius * circleDistance)
return distance
end
var number = new int[] { 10, 200, 300, 400, 500 };
//查詢 number[i] > 300 的數值
var where = number.Where(p => p > 300);
foreach( var item in where)
{
System.Diagnostics.Debug.WriteLine("where item = " + item);
}
//是否有 number[i] == 200 的數值
var any = number.Any(p => p == 200);
System.Diagnostics.Debug.WriteLine("any number[i] == 200 : " + any);
//是否全部都是 number[i] == 300
var all = number.All(p => p == 300);
System.Diagnostics.Debug.WriteLine("all number[i] == 300 : " + all);
//提取資料 並且和成新資料
var select = number.Select(p => "tim"+p).ToArray();
foreach (var item in select)
{
System.Diagnostics.Debug.WriteLine("select item = " + item);
}