首页 > 其他分享 >table常用工具函数 - 表用法

table常用工具函数 - 表用法

时间:2023-05-17 23:23:13浏览次数:32  
标签:function end nil 常用工具 用法 return table tb

 table_ext.lua

---如果table不为空则新建
function table.getEmptyTable(tb)
    if nil == tb or nil ~= next(tb) then
        return {}
    end
    return tb
end

function table.isEmpty(tb)
    return nil == tb or nil == next(tb)
end

function table.swap(tb, k1, k2)
    local temp = tb[k1]
    tb[k1] = tb[k2]
    tb[k2] = temp
end

function table.mergeTable(tb, mergeTb)
    local count = 0
    for k, v in pairs(mergeTb) do
        tb[k] = v
        count = count + 1
    end
    return tb, count
end

查找

function table.findItem(tb, item)
    for k, v in pairs(tb) do
        if v == item then
            return k, v
        end
    end
    return nil
end

function table.findMatch(tb, matchFunc)
    for k, v in pairs(tb) do
        if matchFunc(k, v) then
            return k, v
        end
    end
    return nil
end

function table.ipairsFindItem(tb, item)
    for i, v in ipairs(tb) do
        if v == item then
            return i, v
        end
    end
    return -1
end

function table.ipairsFindMatch(tb, matchFunc)
    for i, v in ipairs(tb) do
        if match(i, v) then
            return i, v
        end
    end
    return -1
end

 

标签:function,end,nil,常用工具,用法,return,table,tb
From: https://www.cnblogs.com/sailJs/p/17407611.html

相关文章

  • jcmd常用用法
    jvmcommand用于将诊断命令请求发送到正在运行的java虚拟机,从jdk7开始提供。是一个功能全面的工具,可用于获取目标java进程的性能统计,jfr,内存使用,垃圾收集,线程堆栈,jvm运行时间。C:\Users\user>jcmd-hUsage:jcmd<pid|mainclass><command...|PerfCounter.print|-ffile>o......
  • datatable中的列头是不区分大小的,== 大写小写均可。
    代码:DataTabledataTable=newDataTable();dataTable.Columns.Add("ID");DataRowdataRow=dataTable.NewRow();dataRow.ItemArray=new[]{"111"};dataTable.Rows.Add(dataRow);Console.WriteLine(dataTable.Rows[0]["id"].ToString());//......
  • Vue ElementUI中 table单元格使用多个Popover解决多行溢出隐藏鼠标悬浮提示问题
    Popover的简单介绍trigger属性用于设置何时触发Popover,支持四种触发方式:hover,click,focus和manual。对于触发Popover的元素,有两种写法:使用slot=“reference”的具名插槽,或使用自定义指令v-popover指向Popover的索引ref。placement弹框的出现位置value/v-model状态......
  • 【React】react-json-view用法
    react-json-view:前端json可视化插件安装:npminstall--savereact-json-view 使用:importReactJsonfrom'react-json-view'<ReactJson/>配置:<ReactJsoncollapsed={false}//是否收起,true为收起indentWidth={10}//缩进iconStyle='cir......
  • 【React+Antd】 可展开Table
    在antd基础上进行改造,抛弃之前的靠前面+进行展开的方式,在操作列进行点击展开  import{Table}from'antd';importReact,{useState}from'react';import'antd/dist/antd.css';import'./index.css';constAPP=()=>{const[expandedRowKeys,se......
  • < Python全景系列-3 > Python控制流程盘点及高级用法、神秘技巧大揭秘!
    欢迎来到我们的系列博客《Python全景系列》!在这个系列中,我们将带领你从Python的基础知识开始,一步步深入到高级话题,帮助你掌握这门强大而灵活的编程语法。无论你是编程新手,还是有一定基础的开发者,这个系列都将提供你需要的知识和技能。 这是系列第三篇,在这篇文章中我们将全面深......
  • 记录内网Docker启动Stable-Diffusion遇到的几个坑
    摘要:最近看到K8s启动stable-diffusion的文章,想着在自己开发环境复现一下。没想到在内网环境还遇到这么多问题,记录一下。本文分享自华为云社区《内网Docker启动Stable-Diffusion(AI作画)》,作者:tsjsdbd。最近看到K8s启动stable-diffusion的文章,想着在自己开发环境复现一下。没想到......
  • Row size too large. The maximum row size for the used table type, not counting B
    问题描述新建表或者修改表varchar字段长度的时候,出现这个错误Rowsizetoolarge.Themaximumrowsizefortheusedtabletype,notcountingBLOBs,is65535.Thisincludesstorageoverhead,checkthemanual.YouhavetochangesomecolumnstoTEXTorBLOBs......
  • dpkg命令用法、Ubuntu下deb包的解压、打包、安装、卸载及常用命令参数
    dpkg命令的用法不带图简装:https://blog.csdn.net/wanghuohuo13/article/details/78916821?ops_request_misc=&request_id=&biz_id=102&utm_term=dpkg&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-6-.first_rank_v2_pc_rank_v29&am......
  • Android Studio学习日志二,Toast用法
    首先,创建一个util,在ToastUtil里面调用方法在里面编写Toast类的代码,方便以后调用packagecom.example.appdemo.util;importandroid.content.Context;importandroid.widget.Toast;publicclassToastUtil{publicstaticToastmToast;publicstaticvoidsh......