ããå¤æ°ã«ä½ãå ¥ã£ã¦ãããªãã°ã»ã»ã»ãï¼ç¡ãå ¥ã£ã¦ããã®ï¼
- ã¯ããã«
- ä½ãå ¥ã£ã¦ãªããå ¥ã£ã¦ã
- ã¨ã©ã¼ãåºãªãããã«æ¹é ãã
- ifæã®ç°¡åãªä½¿ãæ¹
- ãµã³ãã«ããã°ã©ã ã®è©³ç´°è§£èª¬
- çå½å¤
- ãµã³ãã«ããã°ã©ã ã®è§£èª¬
- ããã°ã©ã ã®æçµå½¢
ã¯ããã«
ååè¨äºãããã°ããæéããã¡ã¾ãããããããéããã§ããããã
ååç´¹ä»ãããyuka3ãããã°ã©ã æ´»ç¨ãã¦ã¾ãï¼
ã·ã³ãã«ã§ä¾¿å©ã§ãããã10æ©åã®åºãããã¯ãæ·ãè©°ãããï¼å¾å¾©ã§2åï¼ãªããããã
> yuka3 10
以ä¸ã®ããã«16æ©åã§ãåé¡ãªãããã ããã®åã®ãããã¯32åï¼= 16 × 2ï¼ãã¿ã¼ãã«ã«æ¸¡ãã®å¿ããªãã§ãã ãããã
> yuka3 16
ã§ããä½åº¦ã使ã£ã¦ãããã¡ã«ãããªãã¨ããããã¾ããã§ããï¼
> yuka3
ã¤ã¾ããå¼æ°ãªãã§ãã®ããã°ã©ã ãå®è¡ãããããã½ã¼ã¹ã³ã¼ãã®13è¡ç®ï¼foræã®çµç«¯å¤ã¯æ°åã§ãªãã¨ããã¾ãããã¨ã¨ã©ã¼ã¡ãã»ã¼ã¸ã表示ãããããã§ããã
ã¡ãã£ã¨13è¡ç®ã確èªãã¾ãããã
for i=1,hosuu do
ã¤ã¾ããå¤æ°hosuuã®å¤ãæ°å¤ã§ã¯ãªãã¨ãããã¯å½ããåã§ãããã6è¡ç®ã§local hosuu = ...
ã®ããã«ã³ãã³ãã©ã¤ã³å¼æ°ãå¤æ°hosuuã«ä»£å
¥ãã¦ãã¾ãããããããå¼æ°ãå
¥åãã¦ãªãã®ã§ããã®å¤ã代å
¥ããå¤æ°hosuuã®å¤ãæ°å¤ãªãããããã¾ããã
ä½ãå ¥ã£ã¦ãªããå ¥ã£ã¦ã
ã§ã¯ä½ãå¤æ°hosuuã«å ¥ã£ã¦ããã®ã§ããããã
çµè«ããè¨ãã¨ä½ãå ¥ã£ã¦ãã¾ããã
ãããæ£ç¢ºã«è¨ãã¨ãä½ããªããã¨ããæ å ±ããã®å¤æ°ã«å ¥ã£ã¦ãã¾ãã
ãããLuaè¨èªã§ã¯ãnilãï¼ãã«ï¼ã¨å¼ã³ã¾ããã¤ã¾ãLuaè¨èªã§ã¯ããä½ããªãï¼ç¡ï¼ããnilã¨ãã¦è¡¨ç¾ããããã§ãããè¦ãã¦ããã¾ãããã1
ãç¡ã(nil)ã¯å½ç¶ãªããæ°å¤ã§ã¯ããã¾ããããã®ããã³ã¼ãã®13è¡ç®ã§ããforæã®çµç«¯å¤ã¯æ°åã§ãªãã¨ããã¾ãããã¨ã¨ã©ã¼ãåºã¦ãã¾ã£ãããã§ããã
表示ãããã¨ã©ã¼ã¡ãã»ã¼ã¸ã¯ããã°ã©ã ã®ãã¹ãçºè¦ããã®ã«å½¹ç«ã¡ã¾ããç¹ã«ã¨ã©ã¼ãçºçããè¡çªå·ã®æ å ±ã¯éè¦ã§ãããã®å ´æãä¸å¿ã«ããªããã®ãããªã¨ã©ã¼ãèµ·ããã®ããã¹ãæ¨æ¸¬ãããã¨ãã§ããããã§ãã2
ã¨ã©ã¼ãåºãªãããã«æ¹é ãã
ããã§ã¯ãã®ãããªã¨ã©ã¼ãã§ãªãããã«ããã°ã©ã ãæ¹é ãã¾ãããã
æ¹é ã®ããæ¹ã¯ããããã®ã§ãããããã§ã¯ããå¤æ°ã®åæå¤ã決ãã¦ããã¦ãå¼æ°ãå ¥åãããã¨ãã ããã®å¤ã«å¤æ´ãããæ¹åããªã¹ã¹ã¡ãã¾ãã
ã¤ã¾ãã次ã®ãããªã¤ã¡ã¼ã¸ã
- ããããããå¤æ°hosuuã®å¤ã6ã«æ±ºãã¦ããï¼æ°å¤ã¯ä½ã§ã好ãã«ã©ããï¼ã
- ããå¼æ°ã«ä½ãå ¥åãããããããå¤æ°hosuuã®å¤ã«ä»£å ¥ããï¼ã¤ã¾ããä½ãå ¥åãããªãã£ããä½ãããªãï¼ã
ã¨ããæµãã§ãã
ifæã®ç°¡åãªä½¿ãæ¹
ãããâ¯â¯â¯ãªãã°ãâ³â³â³ãããã
ããã°ã©ã ã§ã¯ãã®ãããªæ§æããã使ãã¾ãã3 ãã®ãããªæ§æã表è¨ããã«ã¯ããæ¡ä»¶åå² if æããå©ç¨ãã¾ãããã®ifæèªä½ã¯å°ã è¤éãªã®ã§ãããã¾ãã¯ã·ã³ãã«ãªããã°ã©ã ã§ifæã®åºæ¬çãªä½¿ãæ¹ãå¦ã³ã¾ãããã
以ä¸ã®ããã°ã©ã ããif0.luaãã¨ããããã°ã©ã åã§ä¿åãã¦ãæ§ã
ãªå¼æ°ãå
¥åãã¦å®è¡ãã¦ã¿ã¾ãããããªãã--
ã§å§ã¾ãè¡ã¯ã³ã¡ã³ãã§ãããè¡ã®éä¸ãã--
ãå
¥ã£ã¦ããã¨ãã¯ãã®--
以éã¯ã³ã¡ã³ãã§ãã
以ä¸ãå®è¡ä¾ã
> if0 10 10
> if0 20 20
> if0 6
ãã®ããã«ã10ãã¨ãã20ãã¨ãå¼æ°ãä¸ãã¦å®è¡ããã¨ããã®å¼æ°ãæçµçã«å¤æ°hosuuã«ä»£å ¥ãã¦ãã®å¤ã表示ãã¾ããã¾ããå¼æ°ãä¸ããªãã¨å¤æ°hosuuã®åæå¤ã§ãã6ããã®ã¾ã¾è¡¨ç¤ºããã¨ããããã°ã©ã ã§ãã
ãµã³ãã«ããã°ã©ã ã®è©³ç´°è§£èª¬
ã¾ã3ã4è¡ç®ã®å¤æ°å®ç¾©é¨åã¯ãããã¾ã§è¨äºãèªã¿é²ãã¦ãã人ãªãã°ä½ãåé¡ãªãç解ã§ããã¨æãã¾ãã
ï¼æ³¨æãããã®ã¯ã3è¡ç®ã®è¡¨è¨ã«ãã£ã¦ãä¸çªç®ã®å¼æ°ããå¤æ°arg1ã«ä»£å ¥ããããã¨ã§ããå¼æ°ãè¤æ°å ¥åãã¦ããä¸çªç®ã®ãã®ã ãåãåºãã¾ãï¼
次ã«ifæã§ãããããã¯æ¬¡ã®ãããªæ§é ããã¦ãã¾ãã
if ãæ¡ä»¶å¼ã then ããã£ã¦æ¬²ãããã¨ï¼è¤æ°ãå¯ï¼ã end
if
ãthen
ãend
ã®3ã¤ã®ãã¼ã¯ã¼ããå¿
é ã§ãã®ã§ä½ç½®ãå«ãã¦ãã£ããã¨è¦ãã¾ãããã
ãã¦ããã®ããã£ã¦æ¬²ãããã¨ãã«ã¤ãã¦ã¯ã好ããªãã¨æ¸ãã°ããã®ã§åé¡ãªãã¨ãã¦ãå°ã£ãã®ã¯ãæ¡ä»¶å¼ãã«ãªãã¾ããããã¯ä½ã§ããããï¼
çå½å¤
Luaè¨èªã«ããããæ¡ä»¶å¼ãã¯ãçµæã¨ãã¦æçµçã«ãçãã¾ãã¯ãå½ãã¨ãªãå¼ãåãæ±ãã¾ãã
ã»ã»ã»ãããé£ããã§ãããã¤ã¾ããã®ãæ¡ä»¶å¼ãã®é¨åã«ã¯çï¼true
ï¼ã¾ãã¯å½ï¼false
ï¼ã®ã©ã¡ããã®å¤ããå
¥ããªãã®ã§ãããçã¨ã¯æ£ãããã¨ãããã¨ããå½ã¨ã¯ééã£ã¦ãããã¨ãããã¨ãæå³ãã¾ãã
ããã¦ãã®çå½å¤ã«ãã£ã¦ãifæã¯æåãå¤ããã®ã§ããï¼
ã¡ãã£ã¨ä¾ã示ãã¾ãããã
if true then print("shinndayo") end
ãã®ããã°ã©ã ã§ã¯ãifæã®ãæ¡ä»¶å¼ãé¨åã«ãç(true
)ããã¯ãè¾¼ã¾ãã¦ãããã ãããã®ifæã¯ç¶ããthen ã endãã®ä¸ãå¦çãããã¨ã«ãªããã ããç»é¢ã«"shinndayo"ã表示ããã
if false then print("shinndayo") end
éã«ãã®ããã°ã©ã ã§ã¯ãifæã®ãæ¡ä»¶å¼ãé¨åã«ãå½(false
)ããã¯ãè¾¼ã¾ãã¦ãããã ãããã®ifæã¯ç¶ããthen ã endãã®ä¸ãèªã¿é£ã°ãã¦ä½ãããªããç»é¢è¡¨ç¤ºããªãã
ã¤ã¾ããif ãæ¡ä»¶å¼ã then ããã£ã¦æ¬²ãããã¨ã end
ã¨ããifæã¯ããæ¡ä»¶å¼ãé¨åã«ãçããå
¥ãã¨ããã£ã¦æ¬²ãããã¨ããå®è¡ãããå½ããå
¥ãã¨èªã¿é£ã°ãã¦ãã¾ããããªã®ã§ãã
ãã¦ããã§ããçããå½ãã¨ããã話ãããããã§ãããLuaè¨èªã§ã¯ããå°ããã®çå½å¤ãæè»ã«åãæ±ã£ã¦ãã¦ãtrue
ã»false
以å¤ã«ãçå½ã®åé¡ãåºãèªãã¦ãã¾ããããã次ã®è¡¨ã§èª¬æãã¾ãããã
å½ | ç |
---|---|
false , nil |
ãâãã®2ã¤ä»¥å¤å ¨é¨ |
åºã¾ããnil
ãããã¯ãç¡ããã¨ãã示ãç¹æ®ãªå¤ã§ãããã
Luaè¨èªã§ã¯ããã®nil
ã¨false
ã¯ãå½ãã¨ãã¾ãã
ããã¦ãã以å¤ã®å
¨é¨ã®å¤ããçãã¨ãã¾ãã4
åç´æå¿«ï¼ï¼ã·ã³ãã«ï¼ï¼
ããããã§å ¨ä½ã説æããããã®ãã¼ãã®èª¬æãæãã¾ãããã¾ã¨ãã¾ãããã
ãµã³ãã«ããã°ã©ã ã®è§£èª¬
ãµã³ãã«ããã°ã©ã ãåæ²ãã¾ãã
ã¾ãã3è¡ç®ã§å¤æ°arg1
ã®ä¸ã«å¼æ°ã®ä¸çªç®ã代å
¥ãã¦ãã¾ãã
ããããã°ã©ã å®è¡æã«å¼æ°ãå
¥åãã¦ããã°ããã«ã¯ãä½ãï¼çï¼ãã代å
¥ããã¦ãããã¨ã«ãªãã¾ããéã«å¼æ°ãå
¥åããã¦ããªããã°ããnilï¼å½ï¼ãã代å
¥ããã¦ã¾ãã
4è¡ç®ã¯ãå¤æ°hosuu
ã®åæå¤ã¨ãã¦6ãè¨å®ãã¦å®ç¾©ãã¦ãã¾ããã
ããã6è¡ç®ã®ifæã¨ãã®æ¡ä»¶å¼ã§ããä»åæ¡ä»¶å¼ã«ã¯arg1
ãã¯ãããã§ããããã§ãããçãå½ãã§ifæã¯æ¡ä»¶åå²ããããã§ããã
ãå¼æ°ãå ¥åããããçãã®ä¸çãããå¼æ°ã«ä½ããå ¥åãã¦ããã°ãarg1ã¯çãªã®ã§ããthen ã endãé¨åãå®è¡ããã¾ãã
ã¤ã¾ããhosuu = arg1
ã§ãããarg1ã®å¤ãhosuuã«ä»£å
¥ãã¾ã5ã
ãã®çµæãåæå¤ã6ã ã£ãhosuuã¯ãå¼æ°ã®å¤ã«ãã£ã¦ä¸æ¸ãããã¾ããã
10è¡ç®ãæçµçã«ç»é¢ã«ã¯ãå ¥åããå¼æ°ããã®ã¾ã¾è¡¨ç¤ºããã¾ãã
ãå¼æ°ãå ¥åãããªãã£ããå½ãã®ä¸çããã¦éã«ãå¼æ°ãå ¥åãããªãã£ããarg1ã¯nilã§ããå½ãªã®ã§ãthen ã endãã¯èªã¿é£ã°ããã¦ä¸ã®è¡ã«é²ã¿ã¾ãã
ãã®çµæãåæå¤6ã ã£ãhosuuã¯æä»ãããã®ã¾ã¾ã§ãã
10è¡ç®ãæçµçã«ç»é¢ã«ã¯ãåæå¤6ããã®ã¾ã¾è¡¨ç¤ºããã¾ãã
ããã°ã©ã ã®æçµå½¢
ããã¾ã§ã®èª¬æãåæ ãã¦æ¹é ãããyuka4ãããã°ã©ã ã§ãã
便å©ã«ä½¿ãåãã¾ããããããã¦ãä¸ä¾¿ãªã¨ãããè¦ã¤ãã¾ãããã
次åã¯ãã£ã¨ä¾¿å©ã«æ¹é ãã¾ãã
-
ããã°ã©ã è¨èªã«ãã£ã¦ã¯ãä½ãä»£å ¥ãã¦ããªãå¤æ°ï¼åæåãã¦ãªãå¤æ°ï¼ã®ä¸ã«ä½ãå ¥ã£ã¦ããã®ãä¸å®ãªå ´åãããã¾ããå®éã«ä¸ãè¦ãã¾ã§ä½ãããããªãã¨ãæã£ï¼ãLuaè¨èªã§ã¯ãä½ãä»£å ¥ãã¦ããªãå¤æ°ã®ä¸èº«ã¯ãç¡ãï¼nilï¼ã¨æ±ºã¾ã£ã¦ãã¾ãã↩
-
å®éã«ã¨ã©ã¼ãèµ·ããã®ã¯ãããã«ãã®è¡ãªã®ã§ããããã®ã¨ã©ã¼ã®æ ¹æ¬çãªåå ã¯ãããããåã«ãããã¨ãå¤ããã¨ãããã¨ã¯è¦ãã¦ããã¾ããããä»åã®ä¾ã§è¨ããªãã°ãã13è¡ç®ã®ã¨ã©ã¼ã®åå ãã¯ã6è¡ç®ã§å¼æ°ãå¤æ°ã«ä»£å ¥ãã¦ããããã©ããããå¼æ°ãå ¥åãã¦ãªãã£ããã§ãã↩
-
ã³ã³ãã¥ã¼ã¿ã®ä¸çã§ã¯ãã³ã¼ãä¸ã«ãããâ¯â¯â¯ãªãã°â³â³â³ããããã¨ããæ¸ããã¦ããªãã£ãå ´åããâ¯â¯â¯ã§ã¯ãªãã¨ããã«ã¯ãä½ããã¾ããããã¤ã¾ãã³ã³ãã¥ã¼ã¿ã¯ãå½ä»¤ãããªãéãä½ãããªãã¨ããã®ãåååä½ã¨ãªãã¾ãã↩
-
nil
,false
以å¤ã®å ¨é¨ã®å¤ããçãã¨ããã®ã¯ã¨ã¦ãã·ã³ãã«ã§ãããæå¤ã¨ãããã®ã§ãããã¨ãã°æ°å¤1
ã0
ãæåå"abc"
ã¯å½ç¶ãªããçã¨ãã¦ãæåå"false"
ãçã¨ãªãã¾ãï¼"“ã§å²ãã§ããã®ããã¤ã³ãï¼ãã¾ãæååå³""
ãçã§ãï¼ããã¯ä¸èº«ã空ã£ã½ã®æååã§ç©ºæåã¨å¼ã³ã¾ãï¼ãããããï¼↩ -
ãã®çå·ãæ°å¦ã®ä¸çã«ããããçãããã®æå³ãããªãã§ãããæ°ãã¤ãã¦ï¼ããã°ã©ã è¨èªã®ä¸çã§ã¯ããarg1ã®å¤ãhosuuã«ä»£å ¥ãããã®æå³ã§ä½¿ã£ã¦ãã¾ããç´ããããã§ãããç¾å®ä¸çã£ã¦ãããªãã®ã§ããå²ãåã£ã¦è¦ãã¾ãããã↩