Movatterモバイル変換


[0]ホーム

URL:


跳转到内容
维基词典自由的多语言词典
搜索

模組:Fun/isCallable

維基詞典,自由的多語言詞典
<Module:Fun

此模块缺少說明文檔。請協助創建
相關連結:根頁面根頁面的子頁面本頁面的子頁面链入嵌入包含測試用例沙盒

localdebug_track_module="Module:debug/track"localtable_get_metamethod_module="Module:table/getMetamethod"localrequire=requirelocaltype=typelocalfunctiondebug_track(...)debug_track=require(debug_track_module)returndebug_track(...)endlocalfunctionget_metamethod(...)get_metamethod=require(table_get_metamethod_module)returnget_metamethod(...)end--[==[Return {true} if the input is a function or functor (an object which can be called like a function, because it has a {__call} metamethod).Note: if the input is an object with a {__call} metamethod, but this function is not able to find it because the object's metatable is protected with {__metatable}, then it will return {false} by default, or {nil} if the {allow_maybe} flag is set.]==]returnfunction(obj,allow_maybe)iftype(obj)=="function"thenreturntrueend-- An object is callable if it has a __call metamethod, so try to get it-- with get_metamethod().localsuccess,__call=get_metamethod(obj,"__call")-- If this succeeds, `obj` will only be callable if the __call metamethod is-- a function (i.e. it can't itself be a callable table), so don't recurse-- to check it.if__callandtype(__call)=="function"thenreturntrue-- If not, then the metatable is protected, so it's not possible to know if-- `obj` is callable without actually calling it.elseifnotsuccessthendebug_track("fun/isCallable/protected metatable")ifallow_maybethenreturnnilendendreturnfalseend
来自“https://zh.wiktionary.org/w/index.php?title=Module:Fun/isCallable&oldid=9507641
分类:​

[8]ページ先頭

©2009-2025 Movatter.jp