Module:Sandbox/Yupik

.mw-parser-output .documentation,.mw-parser-output .documentation-metadata{border:1px solid var(--border-color-base,#a2a9b1);background-color:#ecfcf4;color:inhe

Module:Sandbox/Yupik
--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

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.