igdshare 110220: LuaJIT intro

1,968 views
1,916 views

Published on

A simple introduction to Lua and LuaJIT.
In chinese, sorry.

http://blog.igdshare.org
http://www.youtube.com/user/igdshare

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,968
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
24
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

igdshare 110220: LuaJIT intro

  1. 1. LuaJIT a Just-in-Time compiler for the language Lua
  2. 2. 誰在用 Lua <ul><li>World of Warcraft
  3. 3. Angry Birds
  4. 4. Civilization 5
  5. 5. Homeworld 2
  6. 6. ...
  7. 7. http://en.wikipedia.org/wiki/Category:Lua-scripted_video_games </li></ul><ul><li>...AND YOU ! (possibly) </li></ul>
  8. 8. 認識 Lua <ul><li>語法簡單、靈活
  9. 9. 速度快
  10. 10. 體積小
  11. 11. 易延展( Lua/C API )
  12. 12.   =>Extensible & Embeddable
  13. 13. 『通常不獨立使用』 </li></ul>
  14. 14. Lua 效能
  15. 15. Lua 效能
  16. 16. LuaJIT <ul><li>http://luajit.org
  17. 17. Michael (Mike) Pall </li></ul><ul><li>2005~ LuaJIT 1.x (stable 1.1.6)
  18. 18. 2009~ LuaJIT 2.0-beta releases
  19. 19. Now =>LuaJIT 2.0-beta6
  20. 20. (google for LuaJIT Roadmap 2011) </li></ul>
  21. 21. Just-in-Time Compiler? <ul><li>即時編譯器
  22. 22. Source code => bytecode => machine code
  23. 23. Java Hotspot
  24. 24. C# .Net
  25. 25. Javascript V8/Trace(Jaeger) Monkey
  26. 26. Python Pypy
  27. 27. ... 還有很多 </li></ul>
  28. 28. JIT 效能
  29. 29. 速度 & 程式碼量
  30. 30. LuaJIT 2.0 <ul><li>超級快
  31. 31. 只算 interpreter 也比原本快 2x-4x
  32. 32. Lua 5.1 語法完全相同
  33. 33. 丟進去就可以用 ( drop-in replacement )
  34. 34. Beta 已經很穩定
  35. 35. Foreign Function Interface(beta6)
  36. 36. 現在只有 x86/64 版本 </li></ul>
  37. 37. LuaJIT in Games? <ul>The Settlers 7 <li>搶在上市前實裝 LuaJIT2-beta
  38. 38. 個人測試:
  39. 39. Civilization 5 只能用 LuaJIT1
  40. 40. (可能是因為 bytecode 不相容) </li></ul><ul><li>Mike 本人透露,還有很多不能講 ... </li></ul>
  41. 41. LuaJIT 注意事項 <ul><li>Lua table 盡量用,不用怕 overhead
  42. 42. 避免大量的 closure (目前)
  43. 43. 避免只跑幾次的 inner loop
  44. 44. 避免 global object </li></ul><ul><li>for i = 1, 100000000 do
  45. 45.   local t = {'a','b','c'}
  46. 46.   for j = 1, 3 do t[j] = .. end
  47. 47. End -- p.s. 通常這可以被自動 unroll ,但若其 loop 次數是由變數決定就很難講 </li></ul>
  48. 48. LuaJIT 注意事項 <ul><li>避免無謂的暫存物件
  49. 49. 多用 -jv option 查看執行效果
  50. 50. Bytecode 不相容於 Lua 5.1
  51. 51. 不打算積極跟上 Lua 5.2 </li></ul>
  52. 52. LuaJIT 近期重點 <ul><li>Qualcomm 贊助 ARM Port !
  53. 53. Foreign Function Interface ! </li></ul><ul><li>local ffi = require(&quot;ffi&quot;)
  54. 54. ffi.cdef[[
  55. 55. typedef struct { float x,y,z; } SVertex;
  56. 56. int MessageBoxA(void*,char const*,char const*,int);
  57. 57. ]]
  58. 58. ffi.C.MessageBoxA(nil, &quot;Hello world!&quot;, &quot;Test&quot;, 0)
  59. 59. local img = ffi.new(&quot;SVertex[?]&quot;, 100)
  60. 60. img[0].x = 123 </li></ul>
  61. 61. What's to come? <ul><li>2011 年內:   LuaJIT 2.0 正式版與 2.1 測試版   ARM port of LuaJIT 2.0  
  62. 62. About 2.1 :   New Garbage Collector   FFI C-preprocessor (?)
  63. 63.   </li></ul>
  64. 64. What's to come? <ul><li>更遠程: LuaJIT FFI to C++ (!?)
  65. 65. Binding 再也不用額外寫,運算可以幾乎都寫在 Lua 裡 ...
  66. 66. ...Full Lua 3D engines ?
  67. 67. ...Full Lua Triple-A Titles ?  
  68. 68. What's in the next level ? </li></ul>
  69. 69. My 2 Cents: 沒有天天過年的啦 <ul><li>Lua nature1 :沒有統一穩定的電池
  70. 70. Lua nature2 :大概永遠不適合大團隊開發
  71. 71. 因為太簡單,大家自成一套 =>
  72. 72.  結果反而不穩定、難用?
  73. 73. x86/64 、 ARM 以外的平台大概有得等 </li></ul>
  74. 74. Demo Time <ul><li>Game of Life benchmark :
  75. 75.  純邏輯速度比較 C/C++
  76. 76.  加上繪圖速度比較 =>
  77. 77.    GL primitive 、 Vertex Array 、
  78. 78.    VBO 、 PBO
  79. 79.  繪圖加速情況下把邏輯加速關掉
  80. 80. [1] https://github.com/archilifelin/mysandbox/blob/master/lua/lifegame_ffi_sdl_gl.lua
  81. 81. [2] https://github.com/archilifelin/mysandbox/tree/master/cpp/lifegame_sdl </li></ul>
  82. 82. Lua 框架 <ul><li>CoronaSDK
  83. 83. Scripting-Layer for Android (SL4A)
  84. 84. Gamekit (based on Ogre)
  85. 85. ShiVa Engine
  86. 86. Love2D
  87. 87. ...and more </li></ul>
  88. 88. Love2D <ul><li>http://love2d.org
  89. 89. OpenGL 加速的輕量 2D 遊戲框架
  90. 90. Box2D integration
  91. 91. TrueType Font ( no unicode yet )
  92. 92. Pure Lua </li></ul>function love.draw() love.graphics.print('Hello World!', 400, 300) end
  93. 93. Q & A 資料來源 <ul><li>Lua mailing list
  94. 94. http://luajit.org
  95. 95. http://love2d.org
  96. 96. http://en.wikipedia.org
  97. 97. http://shootout.alioth.debian.org </li></ul><ul><li>cubeat dot tw at gmail dot com
  98. 98. http://igdshare.blogspot.com </li></ul>

×