On Tue, Mar 31, 2015 at 3:25 PM, Brenton Horne <brentonhorne77(a)gmail.com>
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.
Note that your table had an error -- the atomic weight of Fluorine is
assigned to symbol 'C' rather than 'F'.