Pinging Jmorgan who I believe knows Lua. (:
Pine
On Mar 31, 2015 2:27 PM, "Brenton Horne" <[email protected]> wrote:
> I have just tried solving this problem myself, using the /Module:Molar
> mass calculator/:
>
> -- Setting up p and args
> local p= {};
> local args
> M= mw.loadData( 'Module:Standard atomic weight' );
> function dotprod(a, b)
> local ret= 0
> for i= 1, #ado
> ret= ret+ a[i] * b[i];
> end
> return ret
> end
> return dotprod(args, M)
>
>
> with /Module:Standard atomic weight/ having the contents:
>
> local M= {}
> M[Ag] = 107.8682 -- Silver (Ag)
> M[As] = 74.921595 -- Arsenic (As)
> M[Au] = 196.966569 -- Gold (Au)
> M[B] = 10.8135 -- Boron (B)
> M[Ba] = 137.327 -- Barium (Ba)
> M[Bi] = 208.9804 -- Bismuth (Bi)
> M[Br] = 79.904 -- Bromine (Br)
> M[C] = 12.0106 -- Carbon (C)
> M[Ca] = 40.078 -- Calcium (Ca)
> M[Cl] = 35.4515 -- Chlorine (Cl)
> M[Co] = 58.933194 -- Cobalt (Co)
> M[Cu] = 63.546 -- Copper (Cu)
> M[C] = 18.998403163 -- Fluorine (F)
> M[Fe] = 55.845 -- Iron (Fe)
> M[Ga] = 69.723 -- Gallium (Ga)
> M[H] = 1.007975 -- Hydrogen (H)
> M[Hg] = 200.592 -- Mercury (Hg)
> M[I] = 126.90447 -- Iodine (I)
> M[K] = 39.0983 -- Potassium (K)
> M[Li] = 6.9675 -- Lithium (Li)
> M[Mg] = 24.3055 -- Magnesium (Mg)
> M[Mn] = 54.938044 -- Manganese (Mn)
> M[N] = 14.006855 -- Nitrogen (N)
> M[Na] = 22.98976928 -- Sodium (Na)
> M[Ni] = 58.6934 -- Nickel (Ni)
> M[O] = 15.9994 -- Oxygen (O)
> M[P] = 30.973761998 -- Phosphorus (P)
> M[Pb] = 207.2 -- Lead (Pb)
> M[Pt] = 195.084 -- Platinum (Pt)
> M[S] = 32.0675 -- Sulfur (S)
> M[Tl] = 204.3835 -- Thallium (Tl)
> M[Zn] = 65.38 -- Zinc (Zn)
> return M
>
> but this gives the Script error:
>
> Script error: You must specify a function to call.
>
> No further details are available.
>
>
> If someone is actually planning on helping me with this I'd like to know
> because I have bad experience with this list and MediaWiki-I list when it
> comes to Lua questions, in that I never seem to get an answer.
>
> On 1/04/2015 5:06 AM, Brenton Horne wrote:
>
>> Hi,
>>
>> I'd like to be able to calculate the molar mass of chemical compounds
>> using a Lua module so that I could use the output in my infoboxes for
>> chemical compounds and drugs alike. The problem is, I haven't the foggiest
>> how to set up a module, even one that sounds so simple. I was hoping that
>> someone may be able to set things up for me, or at least show me how to do
>> so myself^1 if I gave them the basic idea of what I was hoping this module
>> would do.
>>
>> Say we call the module Molar mass calculator (i.e., @ /Module:Molar mass
>> calculator/ on my local Wiki is where its Lua code is and the template that
>> invokes it /Template:Molar mass calculator/^2 ). I was thinking of the Lua
>> module using a pair of vectors one (A⇀\vec{A}) containing the user-defined
>> variables^3 of all 84 chemical elements found in appreciable quantities in
>> nature and the other containing the average atomic mass for all these
>> elements (M⇀\vec{M}). Then doing the Lua equivalent to a dot product (i.e.,
>> A⇀⋅M⇀=∑i=184AiMi\vec{A}\cdot \vec{M} = \sum_{i=0}^{84} A_i M_i) between
>> these two vectors and using the result as the module's output which would
>> then//used by the template as its output.
>>
>>
>> Footnotes
>>
>> 1. Keeping in mind I am a programming noob, especially when it
>> comes to Lua, so talk to me like a maths guy that just
>> understands a little MATLAB, NumPy, SciPy, Python and Wikitext
>> and no other programming languages as this is fairly accurate.
>> 2. /Template:Molar mass calculator/, presently has this Wikitext
>> (hence if a change is required please do alert me to it):
>>
>> {{#invoke:Molar mass calculator}}<noinclude>{{Clr}}
>> {{documentation}}</noinclude>
>>
>> 3. These variables are those provided to /Template:Molar mass
>> calculator/ as arguments. For example, if I want to call the
>> template in a Wiki page it may look like this for Ethanol (C_2
>> H_6 O)
>>
>> {{Molar mass calculator
>> |C = 2
>> |H = 6
>> |O = 1
>> }}
>>
>> and should provide the output of 46.0694 g/mol.
>>
>> Thanks for your time,
>> Brenton
>>
>
> _______________________________________________
> Wikitech-l mailing list
> [email protected]
> https://lists.wikimedia.org/mailman/listinfo/wikitech-l
_______________________________________________
Wikitech-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikitech-l