Thanks for this. What should /Template:Molar mass calculator/ look like? Currently I have:

{{#invoke:Molar mass calculator|calc}}

but this returns a null value when variables are provided.

On 1/04/2015 12:44 PM, Ori Livneh wrote:
On Tue, Mar 31, 2015 at 3:25 PM, Brenton Horne <[email protected]>
wrote:

Thanks, I have also posted this question on Stackoverflow (
http://stackoverflow.com/questions/29377097/lua-module-
for-calculating-the-molar-mass-of-chemical-compounds) someone with Lua
skills but not so much with MediaWiki Lua templating and they gave this
code:

|local  AtomicWeightLookup=  {
  C=  12.01,
  H=  1.001,
  O=  16
}

local  function  Calculate(Input)
  -- Input Example: {C = 2, H = 6, O = 1}
  local  Result=  0
  -- Iterate through Input table
  for  Element,Quantityin  next,Inputdo
   -- If element is not found in table, assume 0 weight.
   local  AtomicWeight=  AtomicWeightLookup[Element]  or  0
   -- Multiply
   Result=  Result+  Quantity*  AtomicWeight
  end
  return  Result
end

-- EXAMPLE
print(Calculate({C=  2,  H=  6,  O=  1}))|

but as you can see there's no variables in here that are set by MediaWiki
templates, but it seems like a decent starting place.

Here you go:
https://test2.wikipedia.org/wiki/Module:Standard_atomic_weight
https://test2.wikipedia.org/wiki/Module:Molar_mass_calculator
demo: https://test2.wikipedia.org/wiki/Module_talk:Molar_mass_calculator

Note that your table had an error -- the atomic weight of Fluorine is
assigned to symbol 'C' rather than 'F'.
_______________________________________________
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

Reply via email to