打开/关闭菜单
打开/关闭个人菜单
未登录
如果您进行任何编辑,您的IP地址会公开展示。

Module:LibraryUtil:修订间差异

来自索尼克百科
添加的内容 删除的内容
imported>Alistair3149
(1 revision imported)
 
Wr讨论 | 贡献
(导入1个版本:​Imported from Star Citizen Wiki)
 
(未显示另一用户的1个中间版本)
第1行: 第1行:
-- Imported from: https://runescape.wiki/w/Module:LibraryUtil

-- <nowiki>
-- <nowiki>
local libraryUtil = require( 'libraryUtil' )
local libraryUtil = require( 'libraryUtil' )

-- libraryUtil is a standard scribunto module, the following commented out code is just to show what is inside it. Documentation about these functions can be found at https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#libraryUtil
--[=[
local libraryUtil = {}

function libraryUtil.checkType( name, argIdx, arg, expectType, nilOk )
if arg == nil and nilOk then
return
end
if type( arg ) ~= expectType then
local msg = string.format( "bad argument #%d to '%s' (%s expected, got %s)",
argIdx, name, expectType, type( arg )
)
error( msg, 3 )
end
end

function libraryUtil.checkTypeMulti( name, argIdx, arg, expectTypes )
local argType = type( arg )
for _, expectType in ipairs( expectTypes ) do
if argType == expectType then
return
end
end
local n = #expectTypes
local typeList
if n > 1 then
typeList = table.concat( expectTypes, ', ', 1, n - 1 ) .. ' or ' .. expectTypes[n]
else
typeList = expectTypes[1]
end
local msg = string.format( "bad argument #%d to '%s' (%s expected, got %s)",
argIdx,
name,
typeList,
type( arg )
)
error( msg, 3 )
end

function libraryUtil.checkTypeForIndex( index, value, expectType )
if type( value ) ~= expectType then
local msg = string.format( "value for index '%s' must be %s, %s given",
index, expectType, type( value )
)
error( msg, 3 )
end
end

function libraryUtil.checkTypeForNamedArg( name, argName, arg, expectType, nilOk )
if arg == nil and nilOk then
return
end
if type( arg ) ~= expectType then
local msg = string.format( "bad named argument %s to '%s' (%s expected, got %s)",
argName, name, expectType, type( arg )
)
error( msg, 3 )
end
end

function libraryUtil.makeCheckSelfFunction( libraryName, varName, selfObj, selfObjDesc )
return function ( self, method )
if self ~= selfObj then
error( string.format(
"%s: invalid %s. Did you call %s with a dot instead of a colon, i.e. " ..
"%s.%s() instead of %s:%s()?",
libraryName, selfObjDesc, method, varName, method, varName, method
), 3 )
end
end
end
]=]


function libraryUtil.makeCheckClassFunction( libraryName, varName, class, selfObjDesc )
function libraryUtil.makeCheckClassFunction( libraryName, varName, class, selfObjDesc )

2023年8月24日 (四) 00:08的最新版本

Module 说明文档[查看][编辑][历史][刷新]
该说明文档嵌入自 Module:LibraryUtil/doc,可通过讨论页面进行更改请求。

Module:LibraryUtil is mostly to keep track of modules using the standard Scributo library libraryUtil. See Module:LibraryUtil on RuneScape Wiki for more details.


-- Imported from: https://runescape.wiki/w/Module:LibraryUtil

-- <nowiki>
local libraryUtil = require( 'libraryUtil' )

function libraryUtil.makeCheckClassFunction( libraryName, varName, class, selfObjDesc )
	return function ( self, method )
		if getmetatable( self ) ~= class then
			error( string.format(
				"%s: invalid %s. Did you call %s with a dot instead of a colon, i.e. " ..
				"%s.%s() instead of %s:%s()?",
				libraryName, selfObjDesc, method, varName, method, varName, method
			), 3 )
		end
	end
end

return libraryUtil
-- </nowiki>
我们提供服务需要使用Cookie。您使用我们的服务,即表示您同意我们使用Cookie。