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
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
Pinging Jmorgan who I believe knows Lua. (:
Pine On Mar 31, 2015 2:27 PM, "Brenton Horne" brentonhorne77@gmail.com 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 Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Thanks, I have also posted this question on Stackoverflow (http://stackoverflow.com/questions/29377097/lua-module-for-calculating-the-m...) 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.
On 1/04/2015 7:41 AM, Pine W wrote:
Pinging Jmorgan who I believe knows Lua. (:
Pine On Mar 31, 2015 2:27 PM, "Brenton Horne" brentonhorne77@gmail.com 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 Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On Tue, Mar 31, 2015 at 3:25 PM, Brenton Horne brentonhorne77@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.
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'.
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 brentonhorne77@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.
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 Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
To get parameters passed to the template, just call :getParent() in the module: example https://test2.wikipedia.org/wiki/Special:Diff/155912
Il 01/04/2015 11:13, Brenton Horne ha scritto:
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 brentonhorne77@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.
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 Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
I have this template within my Chembox {{Molar mass calculator| |Ag ={{{Ag|}}} |As ={{{As|}}} |Au ={{{Au|}}} |B ={{{B|}}} |Ba ={{{Ba|}}} |Bi ={{{Bi|}}} |Br ={{{Br|}}} |C ={{{C|}}} |Ca ={{{Ca|}}} |Cl ={{{Cl|}}} |Co ={{{Co|}}} |Cu ={{{Cu|}}} |F ={{{F|}}} |Fe ={{{Fe|}}} |H ={{{H|}}} |I ={{{I|}}} |K ={{{K|}}} |Li ={{{Li|}}} |N ={{{N|}}} |Na ={{{Na|}}} |Ni ={{{Ni|}}} |O ={{{O|}}} |P ={{{P|}}} |Pt ={{{Pt|}}} |S ={{{S|}}} |Se ={{{Se|}}} |Sr ={{{Sr|}}} |Zn ={{{Zn|}}} }} as each of these element parameters are optional they can be null and even when some parameters are provided I get the script error:
Lua error in Module:Molar_mass_calculator at line 8: attempt to perform arithmetic on a nil value.
Backtrace:
1. *(tail call)*: ? 2. *Module:Molar_mass_calculator:8 http://localhost/mediawiki/index.php?title=Module:Molar_mass_calculator&action=edit#mw-ce-l8*: in function "chunk" 3. *mw.lua:497*: ? 4. *(tail call)*: ? 5. *[C]*: in function "xpcall" 6. *MWServer.lua:87*: in function "handleCall" 7. *MWServer.lua:301*: in function "dispatch" 8. *MWServer.lua:58*: ? 9. *(tail call)*: ? 10. *mw.lua:141*: ? 11. *Module:Infobox:320 http://localhost/mediawiki/index.php?title=Module:Infobox&action=edit#mw-ce-l320*: in function "preprocessArgs" 12. *Module:Infobox:373 http://localhost/mediawiki/index.php?title=Module:Infobox&action=edit#mw-ce-l373*: in function "chunk" 13. *mw.lua:497*: ? 14. *(tail call)*: ? 15. *[C]*: in function "xpcall" 16. *MWServer.lua:87*: in function "handleCall" 17. *MWServer.lua:301*: in function "dispatch" 18. *MWServer.lua:40*: in function "execute" 19. *mw_main.lua:7*: in main chunk 20. *[C]*: ?
any ideas of how to overcome this error?
On 1/04/2015 7:28 PM, Ricordisamoa wrote:
To get parameters passed to the template, just call :getParent() in the module: example https://test2.wikipedia.org/wiki/Special:Diff/155912
Il 01/04/2015 11:13, Brenton Horne ha scritto:
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 brentonhorne77@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.
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 Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Il 01/04/2015 11:52, Brenton Horne ha scritto:
I have this template within my Chembox {{Molar mass calculator| |Ag ={{{Ag|}}} |As ={{{As|}}} |Au ={{{Au|}}} |B ={{{B|}}} |Ba ={{{Ba|}}} |Bi ={{{Bi|}}} |Br ={{{Br|}}} |C ={{{C|}}} |Ca ={{{Ca|}}} |Cl ={{{Cl|}}} |Co ={{{Co|}}} |Cu ={{{Cu|}}} |F ={{{F|}}} |Fe ={{{Fe|}}} |H ={{{H|}}} |I ={{{I|}}} |K ={{{K|}}} |Li ={{{Li|}}} |N ={{{N|}}} |Na ={{{Na|}}} |Ni ={{{Ni|}}} |O ={{{O|}}} |P ={{{P|}}} |Pt ={{{Pt|}}} |S ={{{S|}}} |Se ={{{Se|}}} |Sr ={{{Sr|}}} |Zn ={{{Zn|}}} }} as each of these element parameters are optional they can be null and even when some parameters are provided I get the script error:
Lua error in Module:Molar_mass_calculator at line 8: attempt to perform arithmetic on a nil value.
Backtrace:
- *(tail call)*: ?
- *Module:Molar_mass_calculator:8
http://localhost/mediawiki/index.php?title=Module:Molar_mass_calculator&action=edit#mw-ce-l8*: in function "chunk" 3. *mw.lua:497*: ? 4. *(tail call)*: ? 5. *[C]*: in function "xpcall" 6. *MWServer.lua:87*: in function "handleCall" 7. *MWServer.lua:301*: in function "dispatch" 8. *MWServer.lua:58*: ? 9. *(tail call)*: ? 10. *mw.lua:141*: ? 11. *Module:Infobox:320 http://localhost/mediawiki/index.php?title=Module:Infobox&action=edit#mw-ce-l320*: in function "preprocessArgs" 12. *Module:Infobox:373 http://localhost/mediawiki/index.php?title=Module:Infobox&action=edit#mw-ce-l373*: in function "chunk" 13. *mw.lua:497*: ? 14. *(tail call)*: ? 15. *[C]*: in function "xpcall" 16. *MWServer.lua:87*: in function "handleCall" 17. *MWServer.lua:301*: in function "dispatch" 18. *MWServer.lua:40*: in function "execute" 19. *mw_main.lua:7*: in main chunk 20. *[C]*: ?
any ideas of how to overcome this error?
Have you tried putting "{{#invoke:Molar mass calculator | calc}}" in your Chembox instead of the template?
Well actually after I sent my reply I did this hoping it might overcome this problem, it gave Nada, I'm afraid it still felt I was using a nil value.
On 1/04/2015 10:44 PM, Ricordisamoa wrote:
Il 01/04/2015 11:52, Brenton Horne ha scritto:
I have this template within my Chembox {{Molar mass calculator| |Ag ={{{Ag|}}} |As ={{{As|}}} |Au ={{{Au|}}} |B ={{{B|}}} |Ba ={{{Ba|}}} |Bi ={{{Bi|}}} |Br ={{{Br|}}} |C ={{{C|}}} |Ca ={{{Ca|}}} |Cl ={{{Cl|}}} |Co ={{{Co|}}} |Cu ={{{Cu|}}} |F ={{{F|}}} |Fe ={{{Fe|}}} |H ={{{H|}}} |I ={{{I|}}} |K ={{{K|}}} |Li ={{{Li|}}} |N ={{{N|}}} |Na ={{{Na|}}} |Ni ={{{Ni|}}} |O ={{{O|}}} |P ={{{P|}}} |Pt ={{{Pt|}}} |S ={{{S|}}} |Se ={{{Se|}}} |Sr ={{{Sr|}}} |Zn ={{{Zn|}}} }} as each of these element parameters are optional they can be null and even when some parameters are provided I get the script error:
Lua error in Module:Molar_mass_calculator at line 8: attempt to perform arithmetic on a nil value.
Backtrace:
- *(tail call)*: ?
- *Module:Molar_mass_calculator:8
http://localhost/mediawiki/index.php?title=Module:Molar_mass_calculator&action=edit#mw-ce-l8*:
in function "chunk" 3. *mw.lua:497*: ? 4. *(tail call)*: ? 5. *[C]*: in function "xpcall" 6. *MWServer.lua:87*: in function "handleCall" 7. *MWServer.lua:301*: in function "dispatch" 8. *MWServer.lua:58*: ? 9. *(tail call)*: ? 10. *mw.lua:141*: ? 11. *Module:Infobox:320 http://localhost/mediawiki/index.php?title=Module:Infobox&action=edit#mw-ce-l320*:
in function "preprocessArgs" 12. *Module:Infobox:373 http://localhost/mediawiki/index.php?title=Module:Infobox&action=edit#mw-ce-l373*:
in function "chunk" 13. *mw.lua:497*: ? 14. *(tail call)*: ? 15. *[C]*: in function "xpcall" 16. *MWServer.lua:87*: in function "handleCall" 17. *MWServer.lua:301*: in function "dispatch" 18. *MWServer.lua:40*: in function "execute" 19. *mw_main.lua:7*: in main chunk 20. *[C]*: ?
any ideas of how to overcome this error?
Have you tried putting "{{#invoke:Molar mass calculator | calc}}" in your Chembox instead of the template?
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Any one know how to overcome this problem, or are yas all stumped?
On 1/04/2015 10:46 PM, Brenton Horne wrote:
Well actually after I sent my reply I did this hoping it might overcome this problem, it gave Nada, I'm afraid it still felt I was using a nil value.
On 1/04/2015 10:44 PM, Ricordisamoa wrote:
Il 01/04/2015 11:52, Brenton Horne ha scritto:
I have this template within my Chembox {{Molar mass calculator| |Ag ={{{Ag|}}} |As ={{{As|}}} |Au ={{{Au|}}} |B ={{{B|}}} |Ba ={{{Ba|}}} |Bi ={{{Bi|}}} |Br ={{{Br|}}} |C ={{{C|}}} |Ca ={{{Ca|}}} |Cl ={{{Cl|}}} |Co ={{{Co|}}} |Cu ={{{Cu|}}} |F ={{{F|}}} |Fe ={{{Fe|}}} |H ={{{H|}}} |I ={{{I|}}} |K ={{{K|}}} |Li ={{{Li|}}} |N ={{{N|}}} |Na ={{{Na|}}} |Ni ={{{Ni|}}} |O ={{{O|}}} |P ={{{P|}}} |Pt ={{{Pt|}}} |S ={{{S|}}} |Se ={{{Se|}}} |Sr ={{{Sr|}}} |Zn ={{{Zn|}}} }} as each of these element parameters are optional they can be null and even when some parameters are provided I get the script error:
Lua error in Module:Molar_mass_calculator at line 8: attempt to perform arithmetic on a nil value.
Backtrace:
- *(tail call)*: ?
- *Module:Molar_mass_calculator:8
http://localhost/mediawiki/index.php?title=Module:Molar_mass_calculator&action=edit#mw-ce-l8*:
in function "chunk" 3. *mw.lua:497*: ? 4. *(tail call)*: ? 5. *[C]*: in function "xpcall" 6. *MWServer.lua:87*: in function "handleCall" 7. *MWServer.lua:301*: in function "dispatch" 8. *MWServer.lua:58*: ? 9. *(tail call)*: ? 10. *mw.lua:141*: ? 11. *Module:Infobox:320 http://localhost/mediawiki/index.php?title=Module:Infobox&action=edit#mw-ce-l320*:
in function "preprocessArgs" 12. *Module:Infobox:373 http://localhost/mediawiki/index.php?title=Module:Infobox&action=edit#mw-ce-l373*:
in function "chunk" 13. *mw.lua:497*: ? 14. *(tail call)*: ? 15. *[C]*: in function "xpcall" 16. *MWServer.lua:87*: in function "handleCall" 17. *MWServer.lua:301*: in function "dispatch" 18. *MWServer.lua:40*: in function "execute" 19. *mw_main.lua:7*: in main chunk 20. *[C]*: ?
any ideas of how to overcome this error?
Have you tried putting "{{#invoke:Molar mass calculator | calc}}" in your Chembox instead of the template?
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On Wed, Apr 1, 2015 at 3:36 PM, Brenton Horne brentonhorne77@gmail.com wrote:
Any one know how to overcome this problem, or are yas all stumped?
I've added some error handling to https://test2.wikipedia.org/wiki/Module:Molar_mass_calculator for you; most likely it was trying to use a quantity of empty-string for any elements you didn't specify in your Chembox, which tonumber() converts to nil. You could probably also have had your Chembox pass 0 as a default (e.g. {{{Ag|0}}} instead of {{{Ag|}}}).
If it's still not working, feel free to put your test cases on test2wiki so we can see them directly.
Oh hallelujah it is working! Thank you, not just you Brad but everyone else that helped me with this!
On 2/04/2015 10:27 AM, Brad Jorsch (Anomie) wrote:
On Wed, Apr 1, 2015 at 3:36 PM, Brenton Horne brentonhorne77@gmail.com wrote:
Any one know how to overcome this problem, or are yas all stumped?
I've added some error handling to https://test2.wikipedia.org/wiki/Module:Molar_mass_calculator for you; most likely it was trying to use a quantity of empty-string for any elements you didn't specify in your Chembox, which tonumber() converts to nil. You could probably also have had your Chembox pass 0 as a default (e.g. {{{Ag|0}}} instead of {{{Ag|}}}).
If it's still not working, feel free to put your test cases on test2wiki so we can see them directly.
Oh hey one other thing, how do I get the module to round the result to 3 decimal places?
On 2/04/2015 10:27 AM, Brad Jorsch (Anomie) wrote:
On Wed, Apr 1, 2015 at 3:36 PM, Brenton Horne brentonhorne77@gmail.com wrote:
Any one know how to overcome this problem, or are yas all stumped?
I've added some error handling to https://test2.wikipedia.org/wiki/Module:Molar_mass_calculator for you; most likely it was trying to use a quantity of empty-string for any elements you didn't specify in your Chembox, which tonumber() converts to nil. You could probably also have had your Chembox pass 0 as a default (e.g. {{{Ag|0}}} instead of {{{Ag|}}}).
If it's still not working, feel free to put your test cases on test2wiki so we can see them directly.
Nvm, figured it out by myself, just added http://lua-users.org/wiki/SimpleRound to the function. I updated the https://test2.wikipedia.org/wiki/Module:Molar mass calculator page if you'd like to see my current code (which I have tested btw in my chembox and in my /Template:Molar mass calculator/)
On 2/04/2015 11:07 PM, Brenton Horne wrote:
Oh hey one other thing, how do I get the module to round the result to 3 decimal places?
On 2/04/2015 10:27 AM, Brad Jorsch (Anomie) wrote:
On Wed, Apr 1, 2015 at 3:36 PM, Brenton Horne brentonhorne77@gmail.com wrote:
Any one know how to overcome this problem, or are yas all stumped?
I've added some error handling to https://test2.wikipedia.org/wiki/Module:Molar_mass_calculator for you; most likely it was trying to use a quantity of empty-string for any elements you didn't specify in your Chembox, which tonumber() converts to nil. You could probably also have had your Chembox pass 0 as a default (e.g. {{{Ag|0}}} instead of {{{Ag|}}}).
If it's still not working, feel free to put your test cases on test2wiki so we can see them directly.
wikitech-l@lists.wikimedia.org