Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Yupik
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
--comment --task2 p={} --this is an empty table; all of our modules will probably start with this --in a sense, p is table that holds all the names of the functions --p is the conventional variable for this function p.Namma(frame) --function is a datatype in Lua; when we're calling things from outside the module, use frame return "Dearvva máilbmi!" end --end marks the end of a block in Lua p.Hi = function(frame) -- this is the same as function p.Hi(frame). Some people prefer one way over the other strName = frame.args.name or "Jimbo" --str* is just a hint that a string is expected. args is the list of parameters you passed to that function --boolean ops => lowercase --if first part is not true, read second part return "Dearvva Luas mu ustibiidda! " .. strName .. ".<br>" --don't forget to use the same name for the var here; double dot is the concat operator end --task3 function p.temp(frame) cel = tonumber(frame.args.celsius) or 0 --this is a string; if tonumber can't convert str into number, it returns nil, not the orig value, so it will fail. fah = cel*9/5+32 --here it's not --this will autocache it into a floating point if cel > 10 then --this is a test msg = " ja dat lea liekkas!" --note: space else msg = " ja dat ii gal leat liekkas!" end --this is the end of the test return "Temperatuvra fahrenheitis lea " .. fah .. msg .. "<br>" end --task 4 p.times = function(frame) local num = tonumber(frame.args.num) or 2 local out = num .. " times table<br>" for i = 1, 10 do out = out .. num .. " x " .. i .. ": " .. i * num .. "<br>" end return out end return p --table is Lua's only complex data type; everything is made out of them in Lua --indices in Lua can be any datatype
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Yupik/doc
(
edit
)