Home
Random
Log in
Settings
About Brighter Shores Wiki
Disclaimers
Search
Editing
Module:LibraryUtil
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- <nowiki> 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 ) 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>
Summary:
Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see
Brighter Shores:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Templates used on this page:
Template:DependencyList
(
edit
)
Template:Documentation
(
edit
)
Template:Extension DPL
(
edit
)
Template:No documentation
(
edit
)
Template:PageType
(
edit
)
Module:Array
(
edit
)
Module:DPLlua
(
edit
)
Module:DependencyList
(
edit
)
Module:Documentation
(
edit
)
Module:LibraryUtil
(
edit
)
Module:LibraryUtil/doc
(
edit
)
Module:Paramtest
(
edit
)
Module:Tooltip
(
edit
)
Module:Yesno
(
view source
) (semi-protected)
This page is a member of a hidden category:
Category:Pages using DynamicPageList3 parser function