Dota 2 Wiki

你现在尚未登录,许多功能可能无法正常使用,若已有账号,请登录,若没有,请先注册Twitch账号
目前我们有非常多的待翻译条目,你也可以看一下目前我们需要优先处理的有哪些目前我们有非常多的待翻译条目,你也可以看一下目前我们需要优先处理的有哪些英雄页面的攻略、克制和物品页面的推荐英雄、小贴士等均为社区玩家编写的,你也可以把自己的心得写上去哦。英雄页面的攻略、克制和物品页面的推荐英雄、小贴士等均为社区玩家编写的,你也可以把自己的心得写上去哦。看不懂技能的buff/debuff是哪个跟哪个?鼠标移动到名称上就能看到游戏内显示的名字和描述了。看不懂技能的buff/debuff是哪个跟哪个?鼠标移动到名称上就能看到游戏内显示的名字和描述了。目前我們沒有善於製作其他中文變體的人員,如果您善於或擁有相關技術,請幫忙補充其他中文變體的空白。目前我們沒有善於製作其他中文變體的人員,如果您善於或擁有相關技術,請幫忙補充其他中文變體的空白。

了解更多

Dota 2 Wiki
Advertisement

This module processes the output of Cargo queries. Empty values are removed and in case of no results, nil is returned instead of an empty table.

Performance[]

The module introduces some additional overhead leading to slightly worse performance. Raw mw.ext.cargo.query queries should be used where the automatic stripping of empty strings is not needed.

Module:Cargo mw.ext.cargo
Each call was running for about 3.6e-04 seconds.
    Mean runtime for each set was 3.6e-02 seconds,
    with standard deviation of 1.8e-03 seconds,
    minimum 6.0e-06, maximum 7.0e-06.
    Total time spent was about 3.6e-01 seconds.
Relative load is estimated to 5,579.6.
Each call was running for about 2.3e-04 seconds.
    Mean runtime for each set was 2.3e-02 seconds,
    with standard deviation of 1.6e-03 seconds,
    minimum 8.0e-06, maximum 1.0e-05.
    Total time spent was about 2.3e-01 seconds.
Relative load is estimated to 2,754.4.

Syntax[]

The syntax is identical to the one provided by mw.ext.cargo.



local Cargo = {}

local checkType = require( 'libraryUtil' ).checkType
local cargoQuery = mw.ext.cargo.query

-- Clear empty string values from a given table and all subtables.
--
-- @param tbl
local function clearEmptyValues( tbl )
  local newTbl = {}
  for k,v in pairs( tbl ) do
    if type( v ) == 'table' then
      newTbl[k] = clearEmptyValues( v )
    elseif v ~= '' then
      newTbl[k] = v
    end
  end

  return newTbl
end

-- Run a Cargo query.
--
-- @param tables
-- @param fields
-- @param args
function Cargo.query( tables, fields, args )
  checkType( 'query', 1, tables, 'string' )
  checkType( 'query', 2, fields, 'string' )
  checkType( 'query', 3, args, 'table', true )

  local results = cargoQuery( tables, fields, args )
  results = clearEmptyValues( results )

  return results
end

-- Store values to a Cargo table.
--
-- @param cargoTable
-- @param values
function Cargo.store( cargoTable, values )
  checkType( 'store', 1, cargoTable, 'string' )
  checkType( 'store', 2, values, 'table' )

  local args = {}
  args._table = cargoTable
  for k,v in pairs( values ) do
    k = tostring( k )
    v = tostring( v )
    args[k] = v
  end

  mw.getCurrentFrame():callParserFunction( '#cargo_store', args )
end

return Cargo
Advertisement