모듈:HelloWorld: 두 판 사이의 차이

이삭위키
둘러보기로 이동 검색으로 이동
(새 문서: -- All Lua modules on Wikipedia must begin by defining a variable that will hold their -- externally accessible functions. They can have any name and may also hold data. my_object = {...)
(차이 없음)

2013년 9월 18일 (수) 22:56 판

위키백과에 있는 루아 모듈의 구조들을 보여주는 간단한 예제 함수입니다. 'Hello world'를 출력하는 종류의 비슷한 모듈로써 모듈:Bananas도 있습니다.


-- All Lua modules on Wikipedia must begin by defining a variable that will hold their
-- externally accessible functions. They can have any name and may also hold data.
my_object = {};
 
-- Add a function to the variable. These are callable in Wikipedia via the #invoke command.
-- "frame" will contain the data that Wikipedia sends this function when it is called. 
my_object.hello = function( frame ) 
 
    -- Declare a local variable and assign data to it.
    local str = "Hello World!"  
 
    -- Quit this function and send the information in "str" back to Wikipedia.
    -- The "print" function is not allowed, so all output is accomplished via 
    -- returning strings in this fashion.
    return str    
 
-- End the function.
end
 
-- All modules end by returning the variable containing its functions to Wikipedia.
return my_object
 
-- We can now use this module by calling {{#invoke: HelloWorld | hello }}.
-- The #invoke command begins with the module's name, in this case "HelloWorld",
-- then takes the name of one of its functions as an argument, in this case "hello".