Jump to content

Module talk:Do not move to Commons

Page contents not supported in other languages.
Add topic
From Wikisource
Latest comment: 1 year ago by CalendulaAsteraceae in topic require('strict')

require('strict')

[edit]

@Uzume What does this do? —CalendulaAsteraceae (talkcontribs) 06:50, 1 February 2023 (UTC)Reply

@CalendulaAsteraceae: See Lua reference manual#strict. It's a pseudo-"pragma": it affects the interpretation of the rest of the program. "Pseudo" because it acts at run-time rather than compile-time (I think it's playing tricks by overriding functions on the global metatables, but I'm not sure). It's patterned roughly on Perl's use strict pragma.
Using it is a good practice because it lets you catch your own sloppy coding, and you should habitually add it whenever you create a new Module:. I'm less convinced of the value of bulk adding it to all existing modules, but it does no harm so long as one knows what one is doing (some of our core modules can't use "strict" yet for various reasons). Xover (talk) 07:22, 1 February 2023 (UTC)Reply
@CalendulaAsteraceae Xover is right. Its main effect is to cause errors when your code attempts to write to a global or read from an undefined global (these things can still be accomplished with rawset and rawget which bypass the metatable functions). Here is a good place to look at the source code: strict.lua. You will note its similarity to Module:No globals (Q16748603) (some copies that still exist and are marked deprecated in favor of strict can be found at mw:Module:No globals and c:Module:No globals). It existed locally and at EN WP until recently, see: 11375988 and 141454803. I find it odd that we are discussing this when you lobbied for its deletion and Xover actually did it, see 12758045 and Wikisource:Proposed deletions/Archives/2022#Module:No globals.—Uzume (talk) 10:33, 1 February 2023 (UTC)Reply
Thank you both for the explanation! —CalendulaAsteraceae (talkcontribs) 04:46, 2 February 2023 (UTC)Reply