SlideShare a Scribd company logo
1 of 19
Lua in Games



               Mr. Nguyễn Ngọc Vân
      Ass Software Manager – VNG Corporation
Agenda

1.   Lua & Benefits
2.   Core engine & Lua model
3.   Lua integrations model
4.   Secure Lua code
5.   Disadvantages
1. Lua & Benefits
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
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)
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
2. Core Engine & Lua Model
Configs        Control Flow
  Settings
(XML, INI, T   Game Logic Process
   XT, …)       (Behaviors, AI, …)

                  Core Engine
Configs
  Settings
 (…, LUA)
              Control Flow
              Lua Engine
 LUA Logic
  Process
(Behaviors,    Core Engine
  AI, …)
3. Lua Integrations Model
Lua APIs
 Lua     Core Logic                     Lua Engine
codes   (Logic Flow)                      (LVM)
                        Lua interface


                       Core Engine
• 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
Quick Sample
function 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
        end
end
4. Secure Lua Code
• 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
• 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 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 
Benefits/tutorial of Lua in games

More Related Content

What's hot

Ansible Tutorial For Beginners | What Is Ansible And How It Works? | Ansible ...
Ansible Tutorial For Beginners | What Is Ansible And How It Works? | Ansible ...Ansible Tutorial For Beginners | What Is Ansible And How It Works? | Ansible ...
Ansible Tutorial For Beginners | What Is Ansible And How It Works? | Ansible ...
Simplilearn
 
MMO Design Architecture by Andrew
MMO Design Architecture by AndrewMMO Design Architecture by Andrew
MMO Design Architecture by Andrew
Agate Studio
 

What's hot (18)

Setting up a local WordPress development environment
Setting up a local WordPress development environmentSetting up a local WordPress development environment
Setting up a local WordPress development environment
 
Automating with Ansible
Automating with AnsibleAutomating with Ansible
Automating with Ansible
 
Intro to Massively Multiplayer Online Game (MMOG) Design
Intro to Massively Multiplayer Online Game (MMOG) DesignIntro to Massively Multiplayer Online Game (MMOG) Design
Intro to Massively Multiplayer Online Game (MMOG) Design
 
CUDA vs OpenCL
CUDA vs OpenCLCUDA vs OpenCL
CUDA vs OpenCL
 
Highly available Drupal on a Raspberry Pi cluster
Highly available Drupal on a Raspberry Pi clusterHighly available Drupal on a Raspberry Pi cluster
Highly available Drupal on a Raspberry Pi cluster
 
Ansible Tutorial For Beginners | What Is Ansible And How It Works? | Ansible ...
Ansible Tutorial For Beginners | What Is Ansible And How It Works? | Ansible ...Ansible Tutorial For Beginners | What Is Ansible And How It Works? | Ansible ...
Ansible Tutorial For Beginners | What Is Ansible And How It Works? | Ansible ...
 
Transitioning From SQL Server to MySQL - Presentation from Percona Live 2016
Transitioning From SQL Server to MySQL - Presentation from Percona Live 2016Transitioning From SQL Server to MySQL - Presentation from Percona Live 2016
Transitioning From SQL Server to MySQL - Presentation from Percona Live 2016
 
Open Cloud BBQ - Nano Server
Open Cloud BBQ - Nano ServerOpen Cloud BBQ - Nano Server
Open Cloud BBQ - Nano Server
 
MMO Design Architecture by Andrew
MMO Design Architecture by AndrewMMO Design Architecture by Andrew
MMO Design Architecture by Andrew
 
High Performance Drupal
High Performance DrupalHigh Performance Drupal
High Performance Drupal
 
Empowering developers to deploy their own data stores
Empowering developers to deploy their own data storesEmpowering developers to deploy their own data stores
Empowering developers to deploy their own data stores
 
OGDC2012 A Practical Architecture Design For MMO Casual Game_Mr. An, Ngo Thai
OGDC2012 A Practical Architecture Design For MMO Casual Game_Mr. An, Ngo ThaiOGDC2012 A Practical Architecture Design For MMO Casual Game_Mr. An, Ngo Thai
OGDC2012 A Practical Architecture Design For MMO Casual Game_Mr. An, Ngo Thai
 
Nano Server (ATD 11)
Nano Server (ATD 11)Nano Server (ATD 11)
Nano Server (ATD 11)
 
Extending ansible
Extending ansibleExtending ansible
Extending ansible
 
Introduction to AJAX
Introduction to AJAXIntroduction to AJAX
Introduction to AJAX
 
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
 
Aos canadian tour (YOW) @energizedtech - Manage AzureRM with powershell
Aos canadian tour (YOW)  @energizedtech - Manage AzureRM with powershellAos canadian tour (YOW)  @energizedtech - Manage AzureRM with powershell
Aos canadian tour (YOW) @energizedtech - Manage AzureRM with powershell
 
Building a World in the Clouds: MMO Architecture on AWS (MBL304) | AWS re:Inv...
Building a World in the Clouds: MMO Architecture on AWS (MBL304) | AWS re:Inv...Building a World in the Clouds: MMO Architecture on AWS (MBL304) | AWS re:Inv...
Building a World in the Clouds: MMO Architecture on AWS (MBL304) | AWS re:Inv...
 

Similar to Benefits/tutorial of Lua in games

Lua in games
Lua in gamesLua in games
Lua in games
Son Aris
 
Lua in Games
Lua in GamesLua in Games
Lua in Games
we20
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
Dmitri Nesteruk
 
.Net overviewrajnish
.Net overviewrajnish.Net overviewrajnish
.Net overviewrajnish
Rajnish Kalla
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 
ApacheCon NA 2010 - High Performance Cloud-enabled SCA Runtimes
ApacheCon NA 2010 - High Performance Cloud-enabled SCA RuntimesApacheCon NA 2010 - High Performance Cloud-enabled SCA Runtimes
ApacheCon NA 2010 - High Performance Cloud-enabled SCA Runtimes
Jean-Sebastien Delfino
 

Similar to Benefits/tutorial of Lua in games (20)

Lua in games
Lua in gamesLua in games
Lua in games
 
Lua in Games
Lua in GamesLua in Games
Lua in Games
 
Apache Traffic Server & Lua
Apache Traffic Server & LuaApache Traffic Server & Lua
Apache Traffic Server & Lua
 
High-Performance Computing with C++
High-Performance Computing with C++High-Performance Computing with C++
High-Performance Computing with C++
 
Hkube
HkubeHkube
Hkube
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
 
Exploiting NoSQL Like Never Before
Exploiting NoSQL Like Never BeforeExploiting NoSQL Like Never Before
Exploiting NoSQL Like Never Before
 
01 java intro
01 java intro01 java intro
01 java intro
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
 
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?
 
.Net overviewrajnish
.Net overviewrajnish.Net overviewrajnish
.Net overviewrajnish
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
 
ApacheCon NA 2010 - High Performance Cloud-enabled SCA Runtimes
ApacheCon NA 2010 - High Performance Cloud-enabled SCA RuntimesApacheCon NA 2010 - High Performance Cloud-enabled SCA Runtimes
ApacheCon NA 2010 - High Performance Cloud-enabled SCA Runtimes
 
Using LuaJIT in mid-load web-projects
Using LuaJIT in mid-load web-projectsUsing LuaJIT in mid-load web-projects
Using LuaJIT in mid-load web-projects
 
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
Common Pitfalls of Functional Programming and How to Avoid Them: A Mobile Gam...
 
Near real-time anomaly detection at Lyft
Near real-time anomaly detection at LyftNear real-time anomaly detection at Lyft
Near real-time anomaly detection at Lyft
 
Treasure Data Summer Internship 2016
Treasure Data Summer Internship 2016Treasure Data Summer Internship 2016
Treasure Data Summer Internship 2016
 
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon YangPractical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
Practical IoT Exploitation (DEFCON23 IoTVillage) - Lyon Yang
 
PyData Boston 2013
PyData Boston 2013PyData Boston 2013
PyData Boston 2013
 
[Intuit] Control Everything
[Intuit] Control Everything[Intuit] Control Everything
[Intuit] Control Everything
 

More from action.vn

ComScore - Southeast Asia Digital Future in Focus 2013
ComScore - Southeast Asia Digital Future in Focus 2013ComScore - Southeast Asia Digital Future in Focus 2013
ComScore - Southeast Asia Digital Future in Focus 2013
action.vn
 
Toan canh thuong mai dien tu 2012
Toan canh thuong mai dien tu 2012Toan canh thuong mai dien tu 2012
Toan canh thuong mai dien tu 2012
action.vn
 
White book 2012 - Các vấn đề thương mại/đầu tư và kiến nghị
White book 2012 - Các vấn đề thương mại/đầu tư và kiến nghịWhite book 2012 - Các vấn đề thương mại/đầu tư và kiến nghị
White book 2012 - Các vấn đề thương mại/đầu tư và kiến nghị
action.vn
 
Amazon Annual Report
Amazon Annual ReportAmazon Annual Report
Amazon Annual Report
action.vn
 
HIGH IMPACT ENTREPRENEURS
HIGH IMPACT ENTREPRENEURSHIGH IMPACT ENTREPRENEURS
HIGH IMPACT ENTREPRENEURS
action.vn
 
VC-Corp Intro
VC-Corp IntroVC-Corp Intro
VC-Corp Intro
action.vn
 
Mạng quảng cáo gia tăng hiệu quả cho quảng cáo hiển thị
Mạng quảng cáo gia tăng hiệu quả cho quảng cáo hiển thịMạng quảng cáo gia tăng hiệu quả cho quảng cáo hiển thị
Mạng quảng cáo gia tăng hiệu quả cho quảng cáo hiển thị
action.vn
 
Mobiles share of the mix marketing evolution
Mobiles share of the mix marketing evolutionMobiles share of the mix marketing evolution
Mobiles share of the mix marketing evolution
action.vn
 
Khảo sát lứa tuổi Teen Việt Nam 2012
Khảo sát lứa tuổi Teen Việt Nam 2012Khảo sát lứa tuổi Teen Việt Nam 2012
Khảo sát lứa tuổi Teen Việt Nam 2012
action.vn
 
Creative design for mobile social game
Creative design for mobile social gameCreative design for mobile social game
Creative design for mobile social game
action.vn
 
Balance in SNS by Energy
Balance in SNS by EnergyBalance in SNS by Energy
Balance in SNS by Energy
action.vn
 
Training and developing human resources in a game studio
Training and developing human resources in a game studioTraining and developing human resources in a game studio
Training and developing human resources in a game studio
action.vn
 

More from action.vn (20)

Bao cao tai nguyen Internet VN 2013
Bao cao tai nguyen Internet VN 2013Bao cao tai nguyen Internet VN 2013
Bao cao tai nguyen Internet VN 2013
 
ComScore - Southeast Asia Digital Future in Focus 2013
ComScore - Southeast Asia Digital Future in Focus 2013ComScore - Southeast Asia Digital Future in Focus 2013
ComScore - Southeast Asia Digital Future in Focus 2013
 
comScore's Presentation Google's Think Digital Vietnam 11-Dec-2012
comScore's Presentation Google's Think Digital Vietnam 11-Dec-2012comScore's Presentation Google's Think Digital Vietnam 11-Dec-2012
comScore's Presentation Google's Think Digital Vietnam 11-Dec-2012
 
Toan canh thuong mai dien tu 2012
Toan canh thuong mai dien tu 2012Toan canh thuong mai dien tu 2012
Toan canh thuong mai dien tu 2012
 
White book 2012 - Các vấn đề thương mại/đầu tư và kiến nghị
White book 2012 - Các vấn đề thương mại/đầu tư và kiến nghịWhite book 2012 - Các vấn đề thương mại/đầu tư và kiến nghị
White book 2012 - Các vấn đề thương mại/đầu tư và kiến nghị
 
Amazon Annual Report
Amazon Annual ReportAmazon Annual Report
Amazon Annual Report
 
HIGH IMPACT ENTREPRENEURS
HIGH IMPACT ENTREPRENEURSHIGH IMPACT ENTREPRENEURS
HIGH IMPACT ENTREPRENEURS
 
Bao cao EBI TMDT 2012
Bao cao EBI TMDT 2012Bao cao EBI TMDT 2012
Bao cao EBI TMDT 2012
 
VC-Corp Intro
VC-Corp IntroVC-Corp Intro
VC-Corp Intro
 
Mobile Trends: Cơ hội còn bỏ ngỏ
Mobile Trends: Cơ hội còn bỏ ngỏMobile Trends: Cơ hội còn bỏ ngỏ
Mobile Trends: Cơ hội còn bỏ ngỏ
 
Mobile VAS market in Vietnam
Mobile VAS market in VietnamMobile VAS market in Vietnam
Mobile VAS market in Vietnam
 
Vietnam’s Web in 2012
Vietnam’s Web in 2012Vietnam’s Web in 2012
Vietnam’s Web in 2012
 
Mạng quảng cáo gia tăng hiệu quả cho quảng cáo hiển thị
Mạng quảng cáo gia tăng hiệu quả cho quảng cáo hiển thịMạng quảng cáo gia tăng hiệu quả cho quảng cáo hiển thị
Mạng quảng cáo gia tăng hiệu quả cho quảng cáo hiển thị
 
IDC Q3 2012 Mobile Developer Report
IDC Q3 2012 Mobile Developer ReportIDC Q3 2012 Mobile Developer Report
IDC Q3 2012 Mobile Developer Report
 
Why not to do a startup?
Why not to do a startup?Why not to do a startup?
Why not to do a startup?
 
Mobiles share of the mix marketing evolution
Mobiles share of the mix marketing evolutionMobiles share of the mix marketing evolution
Mobiles share of the mix marketing evolution
 
Khảo sát lứa tuổi Teen Việt Nam 2012
Khảo sát lứa tuổi Teen Việt Nam 2012Khảo sát lứa tuổi Teen Việt Nam 2012
Khảo sát lứa tuổi Teen Việt Nam 2012
 
Creative design for mobile social game
Creative design for mobile social gameCreative design for mobile social game
Creative design for mobile social game
 
Balance in SNS by Energy
Balance in SNS by EnergyBalance in SNS by Energy
Balance in SNS by Energy
 
Training and developing human resources in a game studio
Training and developing human resources in a game studioTraining and developing human resources in a game studio
Training and developing human resources in a game studio
 

Recently uploaded

Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 

Benefits/tutorial of Lua in games

  • 1. Lua in Games Mr. Nguyễn Ngọc Vân Ass Software Manager – VNG Corporation
  • 2. Agenda 1. Lua & Benefits 2. Core engine & Lua model 3. Lua integrations model 4. Secure Lua code 5. Disadvantages
  • 3. 1. Lua & Benefits
  • 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. 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. 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. 2. Core Engine & Lua Model
  • 8. Configs Control Flow Settings (XML, INI, T Game Logic Process XT, …) (Behaviors, AI, …) Core Engine
  • 9. Configs Settings (…, LUA) Control Flow Lua Engine LUA Logic Process (Behaviors, Core Engine AI, …)
  • 11. Lua APIs Lua Core Logic Lua Engine codes (Logic Flow) (LVM) Lua interface Core Engine
  • 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. Quick Sample function 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 end end
  • 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. • Simple code function Add(a, b) return a + b end print(Add(100, 200)) • Byte-code
  • 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 