루아 팁
루아 팁
--   a   _G:
_G.IsEmptyStr = function(str) 
    return str==nil or type(str) ~= "string" or str == "" 
end  
_G.PrintObjPos = function(prefix, obj)
    prefix = prefix or ""
    local l,t,r,b = obj:GetObjPos()
    XLPrint(prefix .. " l=" .. l .. ", t=" .. t .. ", r=" .. r .. ", b=" .. b)
end
--  :
if not IsEmptyStr(obj:GetText()) then  
    PrintObjPos("[Dongyu]", obj)
end  or 작업자 기본값:num = num or 0(a and b) or c의 기능을 구현합니다.num = (num < 0 and 0) or num
 :
a and b  --   a   false,   a,   b
a or b   --   a   true,   a,   blocal function strlength(str)
    --  , 
    str = string.gsub(str, "%%", " ") --  % " "
    local str = string.gsub(str, "[\128-\191]","")
    local _,ChCount = string.gsub(str, "[\192-\255]","")
    local _,EnCount = string.gsub(str, "[^\128-\255]","")
    return ChCount + EnCount
end이 방법은 UTF-8 형식과 관련이 있으며 표준 ASC||코드(영어)는 0-127입니다.중국어는 3자(192-255)(128-191)(128-191)를 차지한다.상세한 상황은 이 문장을 참고할 수 있다
function trim (s) 
    return (string.gsub(s, "^%s*(.-)%s*$", "%1")) 
end--   find   true,   pattern  , 
pos = string.find(str, "%s", 1, true)function split(s, delim)
    if type(delim) ~= "string" or string.len(delim) <= 0 then
        return
    end
    local start = 1
    local t = {}
    while true do
    local pos = string.find (s, delim, start, true) -- plain find
        if not pos then
          break
        end
        table.insert (t, string.sub (s, start, pos - 1))
        start = pos + string.len (delim)
    end
    table.insert (t, string.sub (s, start))
    return t
endlocal t = {"2016", "3", "6"}
print(table.concat(t, "-"))    -- 2016-3-6function print_lua_table (lua_table, indent)
    local function print_func(str)
        XLPrint("[Dongyu] " .. tostring(str))
    end
    if lua_table == nil or type(lua_table) ~= "table" then
        print_func(tostring(lua_table))
        return
    end
    indent = indent or 0
    for k, v in pairs(lua_table) do
        if type(k) == "string" then
            k = string.format("%q", k)
        end
        local szSuffix = ""
        if type(v) == "table" then
            szSuffix = "{"
        end
        local szPrefix = string.rep(" ", indent)
        formatting = szPrefix.."["..k.."]".." = "..szSuffix
        if type(v) == "table" then
            print_func(formatting)
            print_lua_table(v, indent + 1)
            print_func(szPrefix.."},")
        else
            local szValue = ""
            if type(v) == "string" then
                szValue = string.format("%q", v)
            else
                szValue = tostring(v)
            end
            print_func(formatting..szValue..",")
        end
    end
endfunction copy_table(ori_tab)
    if type(ori_tab) ~= "table" then
        return
    end
    local new_tab = {}
    for k,v in pairs(ori_tab) do
        local vtype = type(v)
        if vtype == "table" then
            new_tab[k] = copy_table(v)
        else
            new_tab[k] = v
        end
    end
    return new_tab
end또는
function deepcopy(object)
    local lookup_table = {}
    local function _copy(object)
        if type(object) ~= "table" then
            return object
        elseif lookup_table[object] then
            return lookup_table[object]
        end
        local new_table = {}
        lookup_table[object] = new_table
        for index, value in pairs(object) do
            new_table[_copy(index)] = _copy(value)
        end
        return setmetatable(new_table, getmetatable(object))
    end
    return _copy(object)
endlocal t = {1,2,3,3,5,3,6}
for i,v in ipairs(t) do
    if v == 3 then
        table.remove(t,i)
    end
end
--  ,  3  ,ipairs  ,
-- remove   3  ,ipairs   5   3
local t = {1,2,3,3,5,3,6}
for i=1, #t do
    if t[i] == 3 then
        table.remove(t,i)
        i = i-1
    end
end
--  ,i=i-1  ,i   1   #t,for   i  
local t = {1,2,3,3,5,3,6}
for i=#t, 1, -1 do
    if t[i] == 3 then
        table.remove(t,i)
    end
end
--  , 
local t = {1,2,3,3,5,3,6}
local i = 1
while t[i] do
    if t[i] == 3 then
        table.remove(t,i)
    else
        i = i+1
    end
end
--  ,  i  local function comp(a,b) 
    return a <= b 
end 
table.sort(t,comp) 
--  , :attempt to compare number with nil 
local function comp(a,b) 
    if a == nil or b == nil then 
        return false 
    end 
    return a <= b 
end 
table.sort(t,comp) 
--  , :invalid order function for sorting 
--  , ;a==b가true로 되돌아오는 것은 이런 문제를 일으킬 수 있다.table 때문이다.sort는 빠른 정렬을 위해 경계 검사를 하지 않았습니다.
for (;;) {
    while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2))  //  , i  
    {
        if (i>=u) luaL_error(L, "invalid order function for sorting");
        lua_pop(L, 1);
    }
    while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1))  //  , j  
    {
        if (j<=l) luaL_error(L, "invalid order function for sorting");
        lua_pop(L, 1);
    }
    if (j<i) {
        lua_pop(L, 3);
        break;
    }
    set2(L, i, j);
}위 코드를 보십시오. 만약에 a==b시true로 되돌아오고 경계의 몇 개의 값이 같다면sort_comp는 경계를 넘어서 이상attempt tocomparenumber withnil을 일으킬 때까지 i의 성장을 막을 수 없습니다.a와 b에 대해 비공식 판단을 하더라도 i가 경계를 초과하여 이상인validorderfunctionforsorting을 일으킬 수 있습니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.