Help:Lua Programming

From Pathfinder Wiki
Revision as of 22:36, 25 January 2022 by DesignerThan (talk | contribs) (Added Section "Thought's on speed and memory")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Other languages:
Deutsch • ‎English • ‎español • ‎français

Logical intensive Code was written in the script language Lua. Those scripts are in the Namespace Modules.

Coding Standard's

In this section the coding standard's we are using here on the wiki, are explained.

Variables and their naming

The names of the variables should be written in CamelCase. In Lua every variable which is defined is global, by default. So it is needed to define them with a local infront of the name. The variable scope is limited to section it is defined in. So if you define a variable inside of a function it's only usable inside of it, the same is for loops, if-Statement's and so on.

On the wiki we define constants that can be used inside of the whole Module, outside of every function right at the start of the Module and the need to be prefixed with C_. That way everyone can recognize that it is a constant and it shouldn't be changed. (In future we could think about a module for all constants)

Tables should be prefixed with a small t.

Thought's on speed and memory

Test of Module that calls either a Template or a Module function to get the honor landing page. In both cases the code was started with a invoke statement on an honor subpage. The result's on the leftside are from a Module calling a Template, on the rightside it's a Module calling a Module function. ModuleCalls GetHonorLandingPage OnHonorSubpage Template-Module.png

Test of Template that calls either a Template or a Module function to get the honor landing page. In both cases the code was started on an honor subpage -> without any argument's. The result's on the leftside are from a Template call, on the rightside it's a Module call. TemplateCalls GetHonorLandingPage OnHonorSubpage Template-Module.png

Test of Template that calls either a Template or a Module function to get the honor landing page. In both cases the code was started on a user sandbox page -> with honorname as argument. The result's on the leftside are from a Template call, on the rightside it's a Module call. TemplateCalls GetHonorLandingPage WithArgHonor Template-Module.png

As these test result's show, inside of a Lua Module, it is best to stick with Lua only and call as less Template's as possible. It need's more resources and a little bit more time. For the Template side it is a bit more difficult. Primarily, if it is about time (speed), calling a Template is way faster than calling a Lua Module, BUT the Lua Module need's less resources as you can see at the node count, the post-expand include size and the hightes expansion depth. For the test a really simple Template was used, so for complex templates it may differ and probably be better to do it in Lua.

Resources