SlideShare uma empresa Scribd logo
1 de 104
Baixar para ler offline
Lua
                ~     ~




2010   1   23
Name:
                    Isoparametric
                               Blog:


                http://d.hatena.ne.jp/Isoparametric/




2010   1   23
by Python




2010   1   23
Lua
                                                  Lua                                        TeCGraf


                                                          Lua
C
                                            Lua VM
           MIT License
Lua                                                                                  Lua




                              Pascal



Lua
Python          Ruby                        Lua
           Lua


Lua5.0                                                          GC                 Lua5.1
                         GC                                                     Python
       Ruby                            GC            GC              Lua


           Lua C++                                                         tolua++ Luabind
                   MIT License
2010   1   23
Lua
                                                    Lua                                           TeCGraf


                                                               Lua
C
                                              Lua VM

                                       W
           MIT License
Lua
                                            iki                                           Lua
                                               pe
                                                    dia
                              Pascal



Lua
Python          Ruby                          Lua
           Lua


Lua5.0                                                               GC                 Lua5.1
                         GC                                                          Python
       Ruby                            GC                 GC              Lua


           Lua C++                                                              tolua++ Luabind
                   MIT License
2010   1   23
1993
                Tecgraf

                Tecgraf



                Lua




                C -> Lua -> C


2010   1   23
Python




2010   1   23
Python                 LL
           C
                      C
                 LL




           ANCI C
           C
                                  GC
           JavaScript prototype        Lua
2010   1   23
2010   1   23
Lua



                Lua

                Lua

                Lua

                Lua

                Lua

                Lua   MIT license
2010   1   23
Lua

                http://www.schulze-mueller.de/download/lua-poster-090207.pdf




2010   1   23
Lua

                http://www.schulze-mueller.de/download/lua-poster-090207.pdf




2010   1   23
byPython




2010   1   23
2010   1   23
2010   1   23
2010   1   23
2010   1   23
Web



                      Adobe's Photoshop Lightroom
                                    Ginga middleware
                World of Warcraft




2010   1   23
2010   1   23
2010   1   23
Perl Ruby



                                Python
                                  Lua

                       Python

                Maya        Inkscape
                   Python                            Lua


2010   1   23
Py(ry


                Py(ry 2.6: and as assert break class continue
                def del elif else except exec finally for from
                global if import in is lambda not or pass print
                raise return try while with yield

                Lua 5.1: and break do else elseif end false
                for function if in local nil not or repeat
                return then true until while


                                                   31 vs 21


2010   1   23
Lua

                     VM
                VM




                     GC


2010   1   23
JavaVM .NET       VM
                             VM

                Perl6

                Lua
                        VM



2010   1   23
Lua

                Lua

                Lua C




2010   1   23
Lua




2010   1   23
……
                print(“Hello World”)
                % lua hello.lua




2010   1   23
--
                function fact (n)
                   if n == 0 then
                       return 1
                   else
                       return n * fact(n-1)
                   end
                end

                print("enter a number:")
                a = io.read("*number")
                print(fact(a))
2010   1   23
2010   1   23
2010   1   23
--




2010   1   23
--
                --[[


                ]]




2010   1   23
--     --[[
                       print("Hello!!")
                --[[
                       --]]
                       ↓
                ]]
                       ----[[
                       print("Hello!!")
                       --]]




2010   1   23
--         --[[
                                               print("Hello!!")
                                    --[[
                                               --]]
                                               ↓
                                    ]]
                                               ----[[
                                               print("Hello!!")
                                               --]]
                --[=[
                ...
                ]=]
                          [[   ]]          =
                [[   ]]
2010   1   23
nil
                      number
                          boolean
                        string
                          table
                      function
                                  userdata
                          thread
2010   1   23
nil

                nil                 nil


                      ==nil
                      GC


                           nil

2010   1   23
nil   false
                0                 true
2010   1   23
Patch   ……
                float   long
2010   1   23
“            ” ‘      ’ --
                      Lua




                0




                            immutable
2010   1   23
..


                a = "1" + "1"                    2
                        b = "a" + "b"
                                b = “a” .. “b”




2010   1   23
Lua




2010   1   23
==




2010   1   23
Lua



2010   1   23
1
                0
                    #




2010   1   23
1
                0
                    #




2010   1   23
Lua
                         key       value
                         “x”        9.2
                         nil

                Header                     value
                                           100
                                           200
                               1           300
                                            nil

2010   1   23
Lua       C
                      C

2010   1   23
nil




                ...



2010   1   23
C
                Lua




2010   1   23
local         do~end
                    Lua


                                 local




                do -- do~end
                   local a = 1
                   print(a) --
                end
                print(a) --
2010   1   23
+         -       *       /
            ^         %           -



            < > <= >= == ~=




            and or not
2010   1   23
if   while repeat   for




2010   1   23
if



2010   1   23
if op == “+” then
                    r=a+b
                                                 if
                elseif op == “-” then
                    r=a-b
                elseif op == “*” then
                    r=a*b
                elseif op == “/” then
                    r=a/b
                else
                    error(“invalid operation”)
                end

2010   1   23
while



2010   1   23
while
                local i = 1
                while t[i] do
                    print(t[i])
                    i=i+1
                end




2010   1   23
repeat



2010   1   23
repeat
            --
            repeat
                line = io.read()
            untile line ~= “”
            print(line)
            --                         local


            local sqr = x/2
            repeat
                sqr = (sqr + x/sqr)/2
                local err = math.abs(sqr^2 - x)
            untile err < x/10000 -- err
2010   1   23
for



2010   1   23
--            for
           for i=10,1,-1 do --                    for
              print(i)
           end

           --                  for
           for i,v in ipairs(array) do
              print(v)
           end
           --                 for
                                         ipairs
2010   1   23
break     return

                switch

                continue

                         break     return


                continue               Patch


                                               5.2


2010   1   23
2010   1   23
2010   1   23
(co-routine)




2010   1   23
2010   1   23
2010   1   23
co-




2010   1   23
co-routine




2010   1   23
2010   1   23
……     CAPI




                coroutine.create
                coroutine.resume
                coroutine.running
                coroutine.status
                coroutine.wrap
                coroutine.yield
                                    Lua

2010   1   23
coroutine.status


                suspended


                running


                dead


                normal

2010   1   23
co = coroutine.create(
                function ()
                    print("start")
                    coroutine.yield() --
                   print("resume")
                end
            )
            -- co   type   thread
            coroutine.resume(co) --
            coroutine.resume(co) --



            --> start
            --> resume




2010   1   23
co = coroutine.create(
                                               function ()
            co = coroutine.create(
                                                   print("start")
                function ()
                                                   local c = coroutine.create(
                    print("start")
                                                       function ()
                    coroutine.yield() --
                                                           print("nest coroutine start")
                   print("resume")                         coroutine.yield()
                end                                        print("nest coroutine resume")
            )                                          end
            -- co   type   thread                  )
            coroutine.resume(co) --                coroutine.resume(c)
                                                   coroutine.resume(c)
            coroutine.resume(co) --
                                                   coroutine.yield()
                                                   print("resume")
                                               end
            --> start                      )
            --> resume                     coroutine.resume(co) --
                                           coroutine.resume(co) --



2010   1   23
croutine.create


                croutine.resume


                croutine.yield




2010   1   23
1
                     1   1



                ……




2010   1   23
C Lua




2010   1   23
Lua




                C         Lua
2010   1   23
C Lua




                C           Lua
2010   1   23
Lua C




                C       Lua
2010   1   23
Lua C




                C       Lua
2010   1   23
Lua




                C         Lua
2010   1   23
Lua




                          20


                      C
2010   1   23
2010   1   23
malloc/free/realloc




2010   1   23
KByte

                C
                    →




                    LTR (Lua Tiny RAM) Patch



2010   1   23
dlmalloc



2010   1   23
tolua++   luabind

                tolua++             Lua



                C++

2010   1   23
printf




                Windows




2010   1   23
2010   1   23
2010   1   23
C                         Lua
                C     Lua



                        t = lua_newthread(L);



                                    GC




                Lua
                            GC



2010   1   23
GC
                          GC
                GC




                     GC




2010   1   23
__add, __sub, __mul, __div, __unm
                      ,__mod   ,__pow

                               __eq          ,__lt             ,__le



                tostring              __tostring

                __index



                __newindex



2010   1   23
mt = {}
       mt.__add = function (lhs, rhs)
          print(lhs, rhs, "mt._add")
          return lhs
       end
       hoge = {}
       foo = {}
       setmetatable(hoge, mt) --
       hoge = hoge + foo --
2010   1   23
Lua




                            __mode   ”k”
                      ”v”




2010   1   23
weak = {}
                mt = {__mode="k"} --
                setmetatable(weak,mt) --
                key = {} --
                weak[key] = 1
                key = {} --
                weak[key] = 2
                --
                collectgarbage() --
                for k, v in pairs(weak) do print(v) end
                   --> 2




2010   1   23
_G

                a = “b” _G[“a”] = “b”

                                a[“b”]   a.b

                     _G



2010   1   23
t:hoge()   t.hoge(t)




2010   1   23
Hoge = {value = 0}
                function Hoge:new(c)        h:setValue(100)
                   c = c or {}
                   setmetatable(c, self)
                   self.__index = self
                                            h.setValue(h,100)
                   return c
                end

                function Hoge:setValue(v)
                   self.value = v
                end

                h = Hoge:new()

                print(h.value)
                h:setValue(100)             h
                print(h.value)
                                            Hoge
                --> 0
                --> 100


2010   1   23
2010   1   23
I/O

                OS



2010   1   23
Lua
                                  Lua 5.1.4 (2008-8-22)

                              Lua 5.2 (work2) (2010-1-13)

                5.2


                                      Lua!

                      Patch                         ……

2010   1   23
Lua




2010   1   23
2010   1   23

Mais conteúdo relacionado

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

最速の言語Lua ~Python Hack-a-thon #3~

  • 1. Lua ~ ~ 2010 1 23
  • 2. Name: Isoparametric Blog: http://d.hatena.ne.jp/Isoparametric/ 2010 1 23
  • 4. Lua Lua TeCGraf Lua C Lua VM MIT License Lua Lua Pascal Lua Python Ruby Lua Lua Lua5.0 GC Lua5.1 GC Python Ruby GC GC Lua Lua C++ tolua++ Luabind MIT License 2010 1 23
  • 5. Lua Lua TeCGraf Lua C Lua VM W MIT License Lua iki Lua pe dia Pascal Lua Python Ruby Lua Lua Lua5.0 GC Lua5.1 GC Python Ruby GC GC Lua Lua C++ tolua++ Luabind MIT License 2010 1 23
  • 6. 1993 Tecgraf Tecgraf Lua C -> Lua -> C 2010 1 23
  • 7. Python 2010 1 23
  • 8. Python LL C C LL ANCI C C GC JavaScript prototype Lua 2010 1 23
  • 9. 2010 1 23
  • 10. Lua Lua Lua Lua Lua Lua Lua MIT license 2010 1 23
  • 11. Lua http://www.schulze-mueller.de/download/lua-poster-090207.pdf 2010 1 23
  • 12. Lua http://www.schulze-mueller.de/download/lua-poster-090207.pdf 2010 1 23
  • 14. 2010 1 23
  • 15. 2010 1 23
  • 16. 2010 1 23
  • 17. 2010 1 23
  • 18. Web Adobe's Photoshop Lightroom Ginga middleware World of Warcraft 2010 1 23
  • 19. 2010 1 23
  • 20. 2010 1 23
  • 21. Perl Ruby Python Lua Python Maya Inkscape Python Lua 2010 1 23
  • 22. Py(ry Py(ry 2.6: and as assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while with yield Lua 5.1: and break do else elseif end false for function if in local nil not or repeat return then true until while 31 vs 21 2010 1 23
  • 23. Lua VM VM GC 2010 1 23
  • 24. JavaVM .NET VM VM Perl6 Lua VM 2010 1 23
  • 25. Lua Lua Lua C 2010 1 23
  • 26. Lua 2010 1 23
  • 27. …… print(“Hello World”) % lua hello.lua 2010 1 23
  • 28. -- function fact (n) if n == 0 then return 1 else return n * fact(n-1) end end print("enter a number:") a = io.read("*number") print(fact(a)) 2010 1 23
  • 29. 2010 1 23
  • 30. 2010 1 23
  • 31. -- 2010 1 23
  • 32. -- --[[ ]] 2010 1 23
  • 33. -- --[[ print("Hello!!") --[[ --]] ↓ ]] ----[[ print("Hello!!") --]] 2010 1 23
  • 34. -- --[[ print("Hello!!") --[[ --]] ↓ ]] ----[[ print("Hello!!") --]] --[=[ ... ]=] [[ ]] = [[ ]] 2010 1 23
  • 35. nil number boolean string table function userdata thread 2010 1 23
  • 36. nil nil nil ==nil GC nil 2010 1 23
  • 37. nil false 0 true 2010 1 23
  • 38. Patch …… float long 2010 1 23
  • 39. ” ‘ ’ -- Lua 0 immutable 2010 1 23
  • 40. .. a = "1" + "1" 2 b = "a" + "b" b = “a” .. “b” 2010 1 23
  • 41. Lua 2010 1 23
  • 42. == 2010 1 23
  • 43. Lua 2010 1 23
  • 44. 1 0 # 2010 1 23
  • 45. 1 0 # 2010 1 23
  • 46. Lua key value “x” 9.2 nil Header value 100 200 1 300 nil 2010 1 23
  • 47. Lua C C 2010 1 23
  • 48. nil ... 2010 1 23
  • 49. C Lua 2010 1 23
  • 50. local do~end Lua local do -- do~end local a = 1 print(a) -- end print(a) -- 2010 1 23
  • 51. + - * / ^ % - < > <= >= == ~= and or not 2010 1 23
  • 52. if while repeat for 2010 1 23
  • 53. if 2010 1 23
  • 54. if op == “+” then r=a+b if elseif op == “-” then r=a-b elseif op == “*” then r=a*b elseif op == “/” then r=a/b else error(“invalid operation”) end 2010 1 23
  • 55. while 2010 1 23
  • 56. while local i = 1 while t[i] do print(t[i]) i=i+1 end 2010 1 23
  • 57. repeat 2010 1 23
  • 58. repeat -- repeat line = io.read() untile line ~= “” print(line) -- local local sqr = x/2 repeat sqr = (sqr + x/sqr)/2 local err = math.abs(sqr^2 - x) untile err < x/10000 -- err 2010 1 23
  • 59. for 2010 1 23
  • 60. -- for for i=10,1,-1 do -- for print(i) end -- for for i,v in ipairs(array) do print(v) end -- for ipairs 2010 1 23
  • 61. break return switch continue break return continue Patch 5.2 2010 1 23
  • 62. 2010 1 23
  • 63. 2010 1 23
  • 65. 2010 1 23
  • 66. 2010 1 23
  • 67. co- 2010 1 23
  • 69. 2010 1 23
  • 70. …… CAPI coroutine.create coroutine.resume coroutine.running coroutine.status coroutine.wrap coroutine.yield Lua 2010 1 23
  • 71. coroutine.status suspended running dead normal 2010 1 23
  • 72. co = coroutine.create( function () print("start") coroutine.yield() -- print("resume") end ) -- co type thread coroutine.resume(co) -- coroutine.resume(co) -- --> start --> resume 2010 1 23
  • 73. co = coroutine.create( function () co = coroutine.create( print("start") function () local c = coroutine.create( print("start") function () coroutine.yield() -- print("nest coroutine start") print("resume") coroutine.yield() end print("nest coroutine resume") ) end -- co type thread ) coroutine.resume(co) -- coroutine.resume(c) coroutine.resume(c) coroutine.resume(co) -- coroutine.yield() print("resume") end --> start ) --> resume coroutine.resume(co) -- coroutine.resume(co) -- 2010 1 23
  • 74. croutine.create croutine.resume croutine.yield 2010 1 23
  • 75. 1 1 1 …… 2010 1 23
  • 76. C Lua 2010 1 23
  • 77. Lua C Lua 2010 1 23
  • 78. C Lua C Lua 2010 1 23
  • 79. Lua C C Lua 2010 1 23
  • 80. Lua C C Lua 2010 1 23
  • 81. Lua C Lua 2010 1 23
  • 82. Lua 20 C 2010 1 23
  • 83. 2010 1 23
  • 85. KByte C → LTR (Lua Tiny RAM) Patch 2010 1 23
  • 87. tolua++ luabind tolua++ Lua C++ 2010 1 23
  • 88. printf Windows 2010 1 23
  • 89. 2010 1 23
  • 90. 2010 1 23
  • 91. C Lua C Lua t = lua_newthread(L); GC Lua GC 2010 1 23
  • 92. GC GC GC GC 2010 1 23
  • 93. __add, __sub, __mul, __div, __unm ,__mod ,__pow __eq ,__lt ,__le tostring __tostring __index __newindex 2010 1 23
  • 94. mt = {} mt.__add = function (lhs, rhs) print(lhs, rhs, "mt._add") return lhs end hoge = {} foo = {} setmetatable(hoge, mt) -- hoge = hoge + foo -- 2010 1 23
  • 95. Lua __mode ”k” ”v” 2010 1 23
  • 96. weak = {} mt = {__mode="k"} -- setmetatable(weak,mt) -- key = {} -- weak[key] = 1 key = {} -- weak[key] = 2 -- collectgarbage() -- for k, v in pairs(weak) do print(v) end --> 2 2010 1 23
  • 97. _G a = “b” _G[“a”] = “b” a[“b”] a.b _G 2010 1 23
  • 98. t:hoge() t.hoge(t) 2010 1 23
  • 99. Hoge = {value = 0} function Hoge:new(c) h:setValue(100) c = c or {} setmetatable(c, self) self.__index = self h.setValue(h,100) return c end function Hoge:setValue(v) self.value = v end h = Hoge:new() print(h.value) h:setValue(100) h print(h.value) Hoge --> 0 --> 100 2010 1 23
  • 100. 2010 1 23
  • 101. I/O OS 2010 1 23
  • 102. Lua Lua 5.1.4 (2008-8-22) Lua 5.2 (work2) (2010-1-13) 5.2 Lua! Patch …… 2010 1 23
  • 103. Lua 2010 1 23
  • 104. 2010 1 23