Upgrade to Pro — share decks privately, control downloads, hide ads and more …

獨立遊戲開發者分享會 110220 ─ LuaJIT intro

IGDSHARE
January 09, 2012

獨立遊戲開發者分享會 110220 ─ LuaJIT intro

這是重新上傳第一場 IGDSHARE 時所分享的 LuaJIT 簡介資料,其中有少部份資訊已過時,參考時請注意。

LuaJIT 官方網站 http://luajit.org

IGDSHARE

January 09, 2012
Tweet

More Decks by IGDSHARE

Other Decks in Programming

Transcript

  1. 誰在用 Lua World of Warcraft Angry Birds Civilization 5 Homeworld

    2 ... http://en.wikipedia.org/wiki/Category:Lua-scripted_video_games ...AND YOU!(possibly)
  2. LuaJIT http://luajit.org Michael (Mike) Pall 2005~ LuaJIT 1.x (stable 1.1.6)

    2009~ LuaJIT 2.0-beta releases Now =>LuaJIT 2.0-beta6 (google for LuaJIT Roadmap 2011)
  3. Just-in-Time Compiler? 即時編譯器 Source code => bytecode => machine code

    Java Hotspot C# .Net Javascript V8/Trace(Jaeger) Monkey Python Pypy ...還有很多
  4. LuaJIT 2.0 超級快 只算 interpreter 也比原本快 2x-4x Lua 5.1 語法完全相同

    丟進去就可以用(drop-in replacement) Beta 已經很穩定 Foreign Function Interface(beta6) 現在只有 x86/64 版本
  5. LuaJIT in Games? The Settlers 7 搶在上市前實裝 LuaJIT2-beta 個人測試: Civilization

    5 只能用 LuaJIT1 (可能是因為 bytecode 不相容) Mike 本人透露,還有很多不能講...
  6. LuaJIT 注意事項 Lua table 盡量用,不用怕 overhead 避免大量的 closure(目前) 避免只跑幾次的 inner

    loop 避免 global object for i = 1, 100000000 do  local t = {'a','b','c'}  for j = 1, 3 do t[j] = .. end End --p.s.通常這可以被自動 unroll,但若其 loop 次數是由變數決定就很難講
  7. LuaJIT 近期重點 Qualcomm 贊助 ARM Port! Foreign Function Interface! local

    ffi = require("ffi") ffi.cdef[[ typedef struct { float x,y,z; } SVertex; int MessageBoxA(void*,char const*,char const*,int); ]] ffi.C.MessageBoxA(nil, "Hello world!", "Test", 0) local img = ffi.new("SVertex[?]", 100) img[0].x = 123
  8. What's to come? 2011 年內:  LuaJIT 2.0 正式版與 2.1 測試版

     ARM port of LuaJIT 2.0   About 2.1:  New Garbage Collector  FFI C-preprocessor (?)  
  9. What's to come? 更遠程:LuaJIT FFI to C++ (!?) Binding 再也不用額外寫,運算可以幾乎

    都寫在 Lua 裡... ...Full Lua 3D engines ? ...Full Lua Triple-A Titles ?  What's in the next level ?
  10. Demo Time Game of Life benchmark:  純邏輯速度比較 C/C++  加上繪圖速度比較 =>

      GL primitive、Vertex Array、   VBO、PBO  繪圖加速情況下把邏輯加速關掉 [1] https://github.com/archilifelin/mysandbox/blob/master/lua/lifegame_ffi_sdl_gl.lua [2] https://github.com/archilifelin/mysandbox/tree/master/cpp/lifegame_sdl
  11. Love2D http://love2d.org OpenGL 加速的輕量 2D遊戲框架 Box2D integration TrueType Font(no unicode

    yet) Pure Lua function love.draw() love.graphics.print('Hello World!', 400, 300) end