偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

通過例子學(xué)習(xí)Lua(4)—函數(shù)的調(diào)用

開發(fā) 前端
想想看哪些地方可以用到例e09中提到的配置方法呢?

1.不定參數(shù)

例e07.lua

  1. -- Functions can take a 
  2. -- variable number of 
  3. -- arguments. 
  4. function funky_print (...)   
  5. for i=1, arg.n do   
  6. print("FuNkY: " .. arg[i])   
  7. end   end   
  8. funky_print("one", "two") 

運(yùn)行結(jié)果

FuNkY: one

FuNkY: two

程序說明

* 如果以...為參數(shù), 則表示參數(shù)的數(shù)量不定.

* 參數(shù)將會(huì)自動(dòng)存儲(chǔ)到一個(gè)叫arg的table中.

* arg.n中存放參數(shù)的個(gè)數(shù). arg[]加下標(biāo)就可以遍歷所有的參數(shù).

2.以table做為參數(shù)

例e08.lua

  1. -- Functions with table 
  2.   -- parameters 
  3.   function print_contents(t) 
  4.   for k,v in t do 
  5.   print(k .. "=" .. v) 
  6.   end 
  7.   end 
  8.   print_contents{x=10y=20

運(yùn)行結(jié)果

x=10

y=20

程序說明

* print_contents{x=10, y=20}這句參數(shù)沒加圓括號(hào), 因?yàn)橐詥蝹€(gè)table為參數(shù)的時(shí)候, 不需要加圓括號(hào)

* for k,v in t do 這個(gè)語句是對(duì)table中的所有值遍歷, k中存放名稱, v中存放值

3.把Lua變成類似XML的數(shù)據(jù)描述語言

例e09.lua

  1. function contact(t)   
  2. -- add the contact ‘t’, which is   
  3. -- stored as a table, to a database   
  4. end   
  5. contact {   name = "Game Developer",   
  6. email = "hack@ogdev.net",   
  7. url = "http://www.ogdev.net",   
  8. quote = [[   There are   
  9. 10 types of people   
  10. who can understand binary.]]   
  11. }   contact {   -- some other contact   } 

程序說明

* 把function和table結(jié)合, 可以使Lua成為一種類似XML的數(shù)據(jù)描述語言

* e09中contact{...}, 是一種函數(shù)的調(diào)用方法, 不要弄混了

* [[...]]是表示多行字符串的方法

* 當(dāng)使用C API時(shí)此種方式的優(yōu)勢(shì)更明顯, 其中contact{..}部分可以另外存成一配置文件

4.試試看

想想看哪些地方可以用到例e09中提到的配置方法呢?

原文鏈接:http://tech.it168.com/j/2008-02-14/200802141347503.shtml

責(zé)任編輯:陳四芳 來源: 來自ITPUB論壇
相關(guān)推薦

2013-12-13 16:53:00

Lua腳本語言C++

2013-12-13 15:42:32

Lua腳本語言

2013-12-13 15:48:52

Lua腳本語言

2013-12-12 17:30:03

Lua例子

2013-12-13 16:46:18

Lua腳本語言

2011-08-22 17:25:31

LuaC++函數(shù)

2011-08-29 15:58:51

Lua函數(shù)

2021-01-12 06:42:50

Lua腳本語言編程語言

2011-06-22 14:07:42

Lua

2011-08-23 16:59:16

C++LUA腳本LUA API

2011-08-22 17:13:00

LuaC++函數(shù)

2011-08-23 16:22:45

Lua 4.0函數(shù)

2011-08-23 11:13:56

Lua

2011-08-25 16:47:53

LuaC++ 證書

2011-08-29 15:45:59

Lua函數(shù)

2011-08-23 16:48:41

Lua 5.1API 函數(shù)

2011-08-23 16:14:27

Lua函數(shù)庫函數(shù)

2023-07-26 06:43:07

函數(shù)調(diào)用

2022-10-14 06:45:25

grepLinux

2011-08-23 13:27:46

Luaglobal變量
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)