0
Lua in Games               Mr. Nguyễn Ngọc Vân      Ass Software Manager – VNG Corporation
Agenda1.   Lua & Benefits2.   Core engine & Lua model3.   Lua integrations model4.   Secure Lua code5.   Disadvantages
1. Lua & Benefits
What’s Lua?•   Scripting language•   Works through LVM (Lua Virtual Machine)•   Stack model design•   “Ultimate game scrip...
Lua Benefits•   Free and open source •   Support OOP•   Runs on almost platforms•   Easy to interface with C/C++•   Very ...
Lua Benefits•   Contents can be changed in real-time•   Auto generate contents•   Users can customize/change contents•   F...
2. Core Engine & Lua Model
Configs        Control Flow  Settings(XML, INI, T   Game Logic Process   XT, …)       (Behaviors, AI, …)                  ...
Configs  Settings (…, LUA)              Control Flow              Lua Engine LUA Logic  Process(Behaviors,    Core Engine ...
3. Lua Integrations Model
Lua APIs Lua     Core Logic                     Lua Enginecodes   (Logic Flow)                      (LVM)                 ...
• Lua APIs  – Call to LVM through events/triggers base  – C APIs to work with LVM  – Auxiliary library provides basic func...
Quick Samplefunction OnPlayerUseItem(nItem)        core.InstanceObj(OBJ_KIND_ITEM, nItem)        if item.GetKind() == ITM_...
4. Secure Lua Code
• Compile to byte-code  – Popular use  – Use luaC module included in library  – Modify luaC with keys for more secure• Enc...
• Simple code  function Add(a, b)     return a + b  end  print(Add(100, 200))• Byte-code
5. Disadvantages
• C APIs are too low-level• Error messages are very confusing • No try-catch, no exceptions• Hard to debug• Hard to inter...
Benefits/tutorial of Lua in games
Upcoming SlideShare
Loading in...5
×

Benefits/tutorial of Lua in games

1,736

Published on

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

  • Be the first to like this

No Downloads
Views
Total Views
1,736
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Benefits/tutorial of Lua in games"

  1. 1. Lua in Games Mr. Nguyễn Ngọc Vân Ass Software Manager – VNG Corporation
  2. 2. Agenda1. Lua & Benefits2. Core engine & Lua model3. Lua integrations model4. Secure Lua code5. Disadvantages
  3. 3. 1. Lua & Benefits
  4. 4. What’s Lua?• Scripting language• Works through LVM (Lua Virtual Machine)• Stack model design• “Ultimate game scripting language” (GDC 2010)• Popular uses in games• Runs on most machines and devices• Written in ANSI C and distributed by small library
  5. 5. Lua Benefits• Free and open source • Support OOP• Runs on almost platforms• Easy to interface with C/C++• Very clean C API• Auto memory management (GC)• Powerful, fast and lightweight• Flexible data structure (TABLE)
  6. 6. Lua Benefits• Contents can be changed in real-time• Auto generate contents• Users can customize/change contents• Fast and easy distributed contents• Secure code• Easy to use, embed and learn• Good references
  7. 7. 2. Core Engine & Lua Model
  8. 8. Configs Control Flow Settings(XML, INI, T Game Logic Process XT, …) (Behaviors, AI, …) Core Engine
  9. 9. Configs Settings (…, LUA) Control Flow Lua Engine LUA Logic Process(Behaviors, Core Engine AI, …)
  10. 10. 3. Lua Integrations Model
  11. 11. Lua APIs Lua Core Logic Lua Enginecodes (Logic Flow) (LVM) Lua interface Core Engine
  12. 12. • Lua APIs – Call to LVM through events/triggers base – C APIs to work with LVM – Auxiliary library provides basic functions to check, register, debug, … LVM – Use C APIs to build core functions• Lua Interface – Call to core logic through exports APIs – Provides APIs (game APIs) to work with core logic – Use C APIs to build, register, and exports APIs
  13. 13. Quick Samplefunction OnPlayerUseItem(nItem) core.InstanceObj(OBJ_KIND_ITEM, nItem) if item.GetKind() == ITM_KIND_HP then local nItemHP = item.GetAttribute(ITM_ATTR_HP) local nPlayerHP = player.GetCurrentHP() local nAddHP = 0.2 * nPlayerHP if nAddHP > 0 and nAddHP < player.GetMaxHP() then player.SetCurrentHP(nAddHP) player.Message(Player:..player.GetName().. use item ..item.GetName()) end endend
  14. 14. 4. Secure Lua Code
  15. 15. • Compile to byte-code – Popular use – Use luaC module included in library – Modify luaC with keys for more secure• Encrypted – Little use – Use keys-pair to encrypted – Use signed file, CRC
  16. 16. • Simple code function Add(a, b) return a + b end print(Add(100, 200))• Byte-code
  17. 17. 5. Disadvantages
  18. 18. • C APIs are too low-level• Error messages are very confusing • No try-catch, no exceptions• Hard to debug• Hard to interfaces with unlike C/C++• Once LVM is crashed, it’s not likely to recover and the service is crashed too • Hard to implement reload feature at run-time• For extreme speed, LuaJIT is a good choice 
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×