Module:Static/doc: Difference between revisions

mNo edit summary
No edit summary
Line 19: Line 19:


If the above code sample was stored in <code>Module:foo</code> and then <code><nowiki>{{#Invoke:foo|main}} {{#Invoke:foo|main}}</nowiki></code> would result in <code>1 2</code>.
If the above code sample was stored in <code>Module:foo</code> and then <code><nowiki>{{#Invoke:foo|main}} {{#Invoke:foo|main}}</nowiki></code> would result in <code>1 2</code>.
== Dev spec ==
Because data stored through this module can be invoked by any modules used in the same page. To avoid being interfered with by other modules, a module '''MUST''' store data in their own namespace. For example in "Module:Example":
<syntaxhighlight lang='lua'>
...
    local static = require( 'Module:Static' )
    if not static.Example then
        static.Example = {}
    end
    static.Example.exampleData = 3
...
</syntaxhighlight>
Data stored by a module, must be stored in a sub-table with the same name of that module (capitalize the first letter, and all spaces should be replaced with underscores). This sub-table should being initialized immediately after the invocation of this module.
<includeonly>{{sandbox other||
<includeonly>{{sandbox other||
<!-- Template categories/interwikis here -->
<!-- Template categories/interwikis here -->