WHY (M)RUBY SHOULD BE YOUR NEXT SCRIPTING LANGUAGE? Tomasz Dąbrowski / Rockhard GIC 2016 Poznań

WHAT DO WE WANT?

WHAT DO WE WANT? •

fast iteration times



easy modelling of complex gameplay logic & UI



not reinventing the wheel



mature tools



easy to integrate

WHAT DO WE HAVE?

MY PREVIOUS SETUP •

Lua



not very popular outside gamedev (used to be general scripting language, but now most applications seem to use python instead)



even after many years I haven’t gotten used to its weird syntax (counting from one, global variables by default, etc)



no common standard - everybody uses Lua differently



standard library doesn’t include many common functions (ie. string.split)

WHAT DO WE HAVE? •

as of 2016, Lua is still a gold standard of general game scripting languages



C# (though not scripting) is probably even more popular because of the Unity



Unreal uses proprietary methods of scripting (UScript, Blueprints)



Squirrel is also quite popular (though nowhere near Lua)



AngelScript, Javascript (V8), Python… are possible yet very unpopular choices



and you can always just use C++

MY CRITERIA

POPULARITY •

popularity is not everything



but using a popular language has many advantages



most problems you will encounter have already been solved (many times)



more production-grade tools



more documentation, tutorials, books, etc



most problems you will encounter have already been solved (many times)



this literally means, that you will be able to have first prototype of anything in seconds by just copying and pasting code



(you can also use package manager to do that and then it’s no longer frowned upon)

Much easier for someone new to learn Python/Ruby than Lua • Multiple books not only in English but also in Polish (and other languages) • Even books for kids! •

Javascript

Python

C#

C++

Ruby

Bash d, ende m m ed co lly re for align a u t c e n ot a d 9 t h on e table need

Lua

Squirrel

AngelScript

Javascript

Python

C#

C++

Ruby

Bash d, ende m m ed co lly re for align a u t c e n ot a d 9 t h on e table need

Lua

Squirrel

AngelScript

(ACTUAL) SCRIPTING •

while the compilation phase has its benefits, what I really want to have is super fast iteration time



so I can hot-swap any code at any moment



will prefer dynamic data structures over performance



also important on platforms where you want to hotpatch code over the network (mobile, consoles)

Javascript

Python

C#

C++

Ruby

Bash d, ende m m ed co lly re for align a u t c e n ot a d 9 t h on e table need

Lua

Squirrel

AngelScript

Javascript

Python

C#

C++

Ruby

Bash d, ende m m ed co lly re for align a u t c e n ot a d 9 t h on e table need

Lua

Squirrel

AngelScript

SIZE •

size, and difficulty of embedding



some languages were not designed for embedding - they require multiple files/bundles, custom build steps, etc.



some have huge runtimes you can’t easily get rid of, and some are just huge because they can



you don’t want 50MB of language runtime over your 10MB mobile game

SIZE •

Python2: ~4MB + runtime



Python3: ~5MB + runtime



mruby: ~0.5MB for everything



Lua: ~0.25MB for everything



V8 (Javascript): >10MB, super complicated build process

Javascript

Python

C#

C++

Ruby

Bash d, ende m m ed co lly re for align a u t c e n ot a d 9 t h on e table need

Lua

Squirrel

AngelScript

Javascript

Python

C#

C++

Ruby

Bash d, ende m m ed co lly re for align a u t c e n ot a d 9 t h on e table need

Lua

Squirrel

AngelScript

AND THE WINNER IS…

MRUBY •

Created in 2012, as an embeddable version
 of Ruby



written in portable C (can be included in project just by copying sources)



based on Ruby ISO spec



very minimal standard library, with many common features extracted to optional gems



there is also mrubyc - a version for microcontrollers with 1/10 of the size (~40 KB)

RUBY •

Object-oriented language



Strong dynamic type system



Optimized for programmer’s performance



Primitives: integers, floats, true/false/nil, strings, symbols, arrays, hashes, closures



Clear separation of local, @instance and $global variables



Exception handling

RUBY •

Any function can take a block of code as a parameter, and many builtin functions do that: •



[“John”, “Тим”, “ ”].each do |name|
 print “Hello #{name}”
 end

each is just an instance method of Array

RUBY •

you can easily create your own methods with blocks: def twice
 yield
 yield
 end





 # two different syntax options:
 twice do print “Banana” end
 twice { print “Banana” }



or in this case just use integer builtin: •

2.times { print “Banana” }

MRUBY •

accepts most of the Ruby syntax
 (including 2.3 safe navigation operator)



has a binary precompiled format so you don’t need to provide sources with your game



you can use the same sources with Ruby and mruby, which is very useful for integration with other services and testing



ie. for multiplayer games, you could share your game logic with the backend written in Ruby on Rails

PACKAGES (GEMS) •

ready-to-use code packages, with dependencies



mixed native and ruby code



ruby: packages are dynamic



mruby: packages are static (selected during build)



a lot of ruby features are optionally available as gems, either included with mruby, or separate

PACKAGES (GEMS) •

Lua has luarocks, but it’s not very popular



none of gamedev developers I’ve talked (who uses Lua) is using luarocks (or any external code for that matter)


PACKAGES (GEMS) •

while the number of native mruby gems available now is limited, you can port “big” Ruby gems (though at this stage you will need to check and possible extend stdlib, depending on the kind of code you’re looking for)

MRUBY & RUBY



since mruby code is also valid Ruby, you can use any existing tools to create, debug, profile and test your code

MRUBY VS LUA

MRUBY VS LUA FORWARD AND REVERSE LOOPS •

Lua •

for key, value in ipairs(table) do
 …
 end



-— http://lua-users.org/wiki/IteratorsTutorial
 function ripairs(t)
 idx={}
 for k,v in pairs(t) do
 if type(k)=="number" then idx[#idx+1]=k end
 end
 table.sort(idx)
 local function ripairs_it(t,_)
 if #idx==0 then return nil end
 k=idx[#idx]
 idx[#idx]=nil
 return k,t[k]
 end
 return ripairs_it, t, nil
 end
 
 for key, value in ripairs(table) do
 …
 end

MRUBY VS LUA FORWARD AND REVERSE LOOPS •

but… •

you need to know about the difference between pairs/ipairs



no built-in reverse iterator



key order is neither sorted nor preserved

MRUBY VS LUA FORWARD AND REVERSE LOOPS •

Ruby •

array.each do |value|
 …
 end



array.reverse_each do |value|
 …
 end



hash.sort.each do |key, value|
 …
 end

SOMETHING SIMPLER?

MRUBY VS LUA ARRAY SHALLOW COPY •

Lua function shallowcopy(orig)
 local orig_type = type(orig)
 local copy
 if orig_type == 'table' then
 copy = {}
 for orig_key, orig_value in pairs(orig) do
 copy[orig_key] = orig_value
 end
 else -- number, string, boolean, etc
 copy = orig
 end
 return copy
 end





 new_array = shallowcopy(array)



Ruby •

new_array = array.clone

MRUBY VS LUA •

And I’m not even starting with OOP!



While prototype-based system used in Lua can be quite powerful, it is very complicated for both non-programmers (ie. designers working on scripts) and most coders accustomed to typical OOP



Ruby on the other hand has a powerful object engine, with easy inheritance, encapsulation, mixins (and even hotpatching on class and object level if required)

LUA •

While you certainly can do anything in Lua, there is a lot of code to write and test first



There are many nuances in Lua coding that are easy to miss (like arrays with empty spaces)
 
 
 
 




With (m)ruby I don’t need to worry about this basics

DEMO TIME!

Q&A [email protected]

Tomasz Dąbrowski / Rockhard GIC 2016 Poznań - GitHub

Page 3 ... so I can hot-swap any code at any moment. • will prefer dynamic data structures over performance. • also important on platforms where you want to hotpatch code over the network (mobile, consoles) ... are just huge because they can. • you don't want 50MB of language runtime over your 10MB mobile game ...

374KB Sizes 6 Downloads 41 Views

Recommend Documents

Tomasz Bogdal - GitHub
https1WWgithubGcomWqueezythegreatWCVW. Citizenship. HTML. XHTML. XML. CSS. jQuery. Dojo ... Tomasz Bogdal email / phone number. Agile. TDD.

POSSIBLE ENTROPY FUNCTIONS Tomasz ...
By a topological dynamical system (X, T) we shall mean a compact metric space. X with a continuous map T : X ↦→ X. The set of all invariant measures of such.

GIC Recruitment [email protected]
SC/ST/OBC/PWD candidates. 11.06.2018 TO 14.06.2018. Candidates should apply through On-Line mode only. No other means/mode of application will be.

CppCon 2016 - GitHub
Sep 18, 2016 - using namespace boost::asio; int main(). { auto host = "echo.websocket.org"; io_service ios; ip::tcp::resolver r{ios}; ip::tcp::socket sock{ios};.

Vowpal Wabbit 2016 - GitHub
Community. 1. BSD license. 2. Mailing list >500, Github >1K forks, >1K,. >1K issues, >100 contributors. 3. The official strawman for large scale logistic regression @ NIPS :-) ...

FALL even (2016) - GitHub
Equations. MATH 665 Topics in. Graduate Mathematics. MATH 665 Topics in. Graduate Mathematics. MATH 611 Mathemati- cal Physics. MATH 612 Mathemati-.

CppCon 2016 - GitHub
Sep 18, 2016 - Send and receive WebSocket messages. ○ Build clients or servers, sync or async. ○ Production-level performance. ○ Autobahn|Testsuite: ...

POSSIBLE ENTROPY FUNCTIONS Tomasz ...
hand, we can now ignore some technical details responsible for minimality of the ..... of course, also a Toeplitz function (into an appropriate product alphabet), ...

ENTROPY STRUCTURE Tomasz Downarowicz May 11 ...
May 11, 2004 - In the last section we will also address the case of noninvertible continuous maps. It is intuitively obvious that chaotic behavior in a topological ...

Playable Experiences at AIIDE 2016 - GitHub
ebrates these efforts and emphasizes the development of polished experiences that ..... Conclusion. AIIDE is a meeting ground between entertainment software.

Eric Evenchick 2016-05-14 - GitHub
May 14, 2016 - April 2018: all cars sold in EU must have eCall. Page 8. CAN Bus. • Controller Area Network. • Low cost, integrated controllers. • Types: • High speed (differential). • Low speed (single ended). • Fault Tolerant. • CAN FD

Sumner Evans September 22, 2016 - GitHub
https://www.git-tower.com/blog/8-reasons-for-switching-to-git. Sumner Evans. Git ... remote, a version of the repository hosted externally from your local machine. ... Play around with a bunch of them and see which one you like best. Here are a few t

Ordinary Differential Equations Autumn 2016 - GitHub
Mar 29, 2017 - A useful table of Laplace transforms: http://tutorial.math.lamar.edu/pdf/Laplace Table.pdf. Comment. Here you finally get the opportunity to practise solving ODE's using the powerful method of Laplace transformations. Please takes note

Ahmet Emre Alada˘g April, 2016 - GitHub
Personal Site: http://www.emrealadag.com. Web Pages. Projects: ... Woramo is a social network for sharing product/service reviews online. Friends ... Server Faces, installed/configured a server with RHEL5 and Oracle 10g En- terprise Server ...

Lecture 11 — November 22, 2016 Volkswagen Emissions ... - GitHub
Emissions Workshop, an academic conference, in May 2014. Regulators and ... “This VW Diesel Scandal is Much Worse Than a Re- call.” 21 September 2015.

Bitcoin Wallet Privacy Rating Report 2nd Edition, March 2016 - GitHub
PaGE 1 table of contents introduction 2. Overall Wallet Privacy Rankings 3 individual .... information directly from nodes in the Bitcoin network By accessing the Bitcoin .... average user prone to snooping from their Internet Service Provider or.

GitHub
domain = meq.domain(10,20,0,10); cells = meq.cells(domain,num_freq=200, num_time=100); ...... This is now contaminator-free. – Observe the ghosts. Optional ...

GitHub
data can only be “corrected” for a single point on the sky. ... sufficient to predict it at the phase center (shifting ... errors (well this is actually good news, isn't it?)

MATH 241 Fall 2016 (3 credits) Course Syllabus - GitHub
Dec 5, 2016 - Thus, I will need the email address that you reliably check. The ... scanning them in as a PDF (sub 2MB) and sending them to me. .... good boost to your grade; I once had a student go from a B to and A- based on these.