Дополнительные действия
Это страница документации Модуль:Class.
Enables equal treatment of Lua and wikicode users for modules. Using this module means you will no longer need to have two different entry points for each function—both Lua and wikicode can call the same function. ==Usage== Using this module is straightforward. Here's an example:
local Class = require('Module:Class') <!--- Add the import local Cool = Class.new() <!--- Create a class function Cool.doCoolStuff(a, b) <!--- Note the colon symbol! return a + b end return Cool.export() <!--- Export the table
Now, doCoolStuff can be called from both Lua and wikicode with the same arguments.
To illustrate, you can use Cool
(2, 3) in Lua, and also use {{#invoke
|doCoolStuff|2|3}} in wikicode, and both will return 5.
===Named Arguments=== When named arguments are provided, there's a slight change. Named arguments are supplied as a Lua table and are always the first argument. Here's how:
local Class = require('Module:Class') <!--- Add the import local Cool = Class.new() <!--- Create a class function Cool.doCoolStuff(args, a, b) <!--- Named args are now the first argument! return a + b + args.c end return Cool.export() <!--- Export the table
You can now call Cool
({c = 5}, 2, 3) in Lua, and similarly use {{#invoke
|doCoolStuff|2|3|c=5}} in wikicode, and both will return 10.
===Advanced Usage=== Module:Class supports advanced usage scenarios via the export function's options parameter. These options are passed directly to the Module:Arguments, allowing you to specify features such as frame inheritance, trimming, and more. For more details, refer to iCCup's Module
documentation.
API
-
Программное имя: Class
Adjusts the provided table so that its public functions (those not prefixed with an underscore) are usable from both Lua and wikicode, and returns the modified table. Note: Avoid creating underscored versions of your public methods—use distinct names. For instance, don't use both copy() and _copy() in the same module. The options parameter allows passing arguments to Module:Arguments's getArgs method.
{{#iccupdb_datapoint:API_Class/doc_export
|type=api
|name=export
|information=
|image=
|date=
|extradata={{#iccupdb_create_json:
|description=Adjusts the provided table so that its public functions (those not prefixed with an underscore) are usable from both Lua and wikicode, and returns the modified table. Note: Avoid creating underscored versions of your public methods—use distinct names. For instance, don't use both copy() and _copy() in the same module. The options parameter allows passing arguments to Module:Arguments's getArgs method.
|params=class: table, options: table
|returns=class
|module=Module
}}
}}
Creates a new class by setting the proper metadata. If a base class is provided, it will be used as the base. An optional init function can act as a constructor. If only init is provided, it functions independently.
{{#iccupdb_datapoint:API_Class/doc_new
|type=api
|name=new
|information=
|image=
|date=
|extradata={{#iccupdb_create_json:
|description=Creates a new class by setting the proper metadata. If a base class is provided, it will be used as the base. An optional init function can act as a constructor. If only init is provided, it functions independently.
|params=base: class, init: function
|returns=class
|module=Module
}}
}}
Посмотрите всю нашу документацию iCCup здесь.