Luarocks Fostering an Ecosystem of Lua Modules
Total Page:16
File Type:pdf, Size:1020Kb
LuaRocks fostering an ecosystem of Lua modules Hisham Muhammad [email protected] @hisham_hm FOSDEM !"# $russels% $elgium &hat is LuaRocks 'ackage manager... like d(kg (a(t*get+% RPM% etc. like Ruby-ems, Python eggs, npm% C'/0% etc. ...for Lua e1tension modules written in Lua (.lua files) or ,inary modules (.so4.dll files) Fostering an ecosystem of Lua modules Some uni5ue challenges ...related to Lua as a language ...related to Lua as a community Lessons learned ...on building an ecosystem / one*slide introduction to Lua function process(filename, fn, ...) local f = io.open(filename) local rets = {} for line in f:lines() do rets[#rets+1] = { fn(line, ...) } end f:close() return rets end matches = process("file.txt", string.find, "foo") for i, match in ipairs(matches) do print(i, table.concat(match, ", ")) end / one*slide introduction to Lua function process(filename, fn, ...) local f = io.open(filename) local rets = {} o,6ects for line in f:lines() do rets[#rets+1] = { fn(line, ...) } end f:close() return rets end matches = process("file.txt", string.find, "foo") for i, match in ipairs(matches) do print(i, table.concat(match, ", ")) end / one*slide introduction to Lua function process(filename, fn, ...) local f = io.open(filename) local rets = {} for line in f:lines() do rets[#rets+1] = { fn(line, ...) } end f:close() return rets 3rst*class functions end matches = process("file.txt", string.find, "foo") for i, match in ipairs(matches) do print(i, table.concat(match, ", ")) end / one*slide introduction to Lua function process(filename, fn, ...) local f = io.open(filename) local rets = {} for line in f:lines() do rets[#rets+1] = { fn(line, ...) } end f:close() return rets iterators end matches = process("file.txt", string.find, "foo") for i, match in ipairs(matches) do print(i, table.concat(match, ", ")) end / one*slide introduction to Lua function process(filename, fn, ...) local f = io.open(filename) local rets = {} for line in f:lines() do rets[#rets+1] = { fn(line, ...) } end f:close() return rets ta,les% ta,les e7ery2here8 end matches = process("file.txt", string.find, "foo") for i, match in ipairs(matches) do print(i, table.concat(match, ", ")) end Lua9 a (eculiar free soft2are (ro6ect Lua9 created at ':.*Rio in $razil, de7elo(ed ,y uni7ersity (rofessors 20 year history M<=4>"1 licensed ?o(en source% closed de7elo(ment" Lua9 a (eculiar community Successful as an em,edded language LuaTe>% &iki(edia, etc. 7ery custom en7ironments 'o(ular in the game industry e7ery2here from /ngry $irds to &o& one-shot (ro6ects% mostly (ro(rietary Lua9 a (eculiar language Su(er light2eight Designed for em,edding (.tar.gz is 272Ki,+ /da(ts itself to your (ro6ect's /'< Doesn't pro7ide many /'<s of its o2n Modules 3ll this gap8 $ut 2here are the modulesC Side*eDects of a minimalistic language9 no standard ,uild system modules 2ere scattered around so*called ?D<E culture? (Lua only got modules in 7ersion 5.0, after "! years of existence8+ /ttem(ting to ,roaden LuaBs hori;ons Ae(ler 'ro6ect% 2006 on2ards research pro6ect to de7elo( a platform for 2e, de7 WSAPI Xavante Orbit Sputnik Copas Cosmo Coxpcall LFS Rings LuaProfiler RemDebug LuaExpat LuaSQL CGILua ... Enter LuaRocks The missing link: a (ackage manager8 <nitial goal: build4de(loy Ke(ler modules on Unix and &indows ...and it gre2 from there 0.4.1 0.5.2 0.4 0.5.1 2.0.7 0.3.2 0.5 2.0.4.1 2.0.6 2.0.8 2.0.10 0.10.2 0.3.1 0.4.3 1.0 2.02.0.1 2.0.4 2.0.7.1 2.0.12 2.1.1 2.1 2.2.0 0.1 0.3 0.4.2 0.6 1.0 1.0.1 2.0 2.0.2 2.0.3 2.0.5 2.0.9 2.0.11 2.0.13 2.1.0 2.1.2 2.2 2007 2008 2009 2010 2011 2012 2013 2014 2015 2007 2008 2009 2010 2011 2012 2013 2014 20 :( and running in one slide8 ~$ wget http://lua.org/ftp/lua-5.3.0.tar.gz ~$ tar zxpf lua-5.3.0.tar.gz ~$ cd lua-5.3.0 ~$ make linux; sudo make install; cd .. ~$ wget http://luarocks.org/releases/luarocks-2.2.0.tar.gz ~$ tar zxpf luarocks-2.2.0.tar.gz ~$ cd luarocks-2.2.0 ~$ ./configure; sudo make bootstrap; cd .. ~$ sudo luarocks install luasocket ~$ lua Lua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio > require "socket" Rocks and rocks(ecs / rock file contains sources or binaries... luafilesystem-1.5.0-2.src.rock lpeg-0.10-2.win32-x86.rock lxsh-0.8.6-1.all.rock ...plus a rocks(ec% 2hich is a specification file9 package = "midialsa"; version = "1.21-0" source = { url = "http://www.pjb.com.au/comp/lua/midialsa-1.21.tar.gz", md5 = "072844348e66c04cee42a5b489784453" } description = { summary = "Provides access to the ALSA sequencer", detailed = "...", homepage = "http://www.pjb.com.au/comp/lua/midialsa.html", license = "MIT/X11" } dependencies = { "lua >= 5.1" } external_dependencies = { ALSA = { header = "alsa/asoundlib.h", library = "asound" } } -- ... /ddressing the lack of standards $uild systems a(lenty9 nothing at all — cmake G autoconf — make G etc. SolutionC $e like Lua9 ada(t to the de7elo(ers' en7ironment $uild ,ack*ends build = { type = "make", LuaRocks can use variables = { PREFIX = "$(PREFIX)", diDerent ,ack*ends for LUALIB = "$(LUA_LIBDIR)", different modules: }, } make% cmake% autoconf... build = { type = "builtin", modules = { &e also added a ["midialsa"] = "midialsa.lua", ["C-midialsa"] = { ,uilt*in ,uild tool sources = { "C-midialsa.c" }, libraries = { "asound" }, incdirs = { "$(ALSA_INCDIR)" }, libdirs = { "$(ALSA_LIBDIR)" }, } }, @#H of all rocks use it! copy_directories = { "doc", "test" } } =he module re(ository Mo7ing to a "re(ository? model aDects9 de7elo(ers it changes the 2orkIo2 for releasing code and it changes ho2 users users setu( their en7ironment our users are de7elo(ers too8 $ootstra((ing a re(ository 'hase "9 .urated re(ository submissions through mailing list help out early ado(ters le7erage LuaRocks via Aepler modules 'hase 9 'u,lic re(ository MoonRocks htt(944rocks.moonscri(t.org greater de7elo(er autonomy Recent gro2th of the re(ository 700 MoonRocks 600 500 400 300 200 100 0 'Sep 2009 'Mar 2010 'Sep 2010 'Mar 2011 'Sep 2011 'Mar 2012 'Sep 2012 'Mar 2013 'Sep 2013 'Mar 2014 'Sep 2014 'Feb 2015 2009 2010 2011 2012 2013 2014 2015 / 7irtuous circle luahue ↳penlight ↳luafilesystem ↳luasocket ↳luajson $reaking the ↳lunit DIY (0<HC) culture ↳lpeg sailor ↳datafile ↳luafilesystem ↳valua ↳lbase64 De7elo(ers are ↳cgilua also users8 lua-jet ↳xavante ↳lua-cjson ↳luasocket ↳lua-websockets ↳copas ↳luabitop ↳coxpcall Less rein7ention ↳copas ↳wsapi-xavante ↳coxpcall ↳wsapi of the wheel ↳luasocket ↳rings ↳lua-ev ↳lpack Latest "! J/00K from lua*l ● J/00K LuaExec ● J/00K .ompat*5.L 0.1 ?luarocks install compat53" ● J/00K lua*fcgi v1.0 ?Eou can install it 2ith luarocks" ● J/00K lua*arc4random 1.0 ?it's on ,oth luarocks and -ithub8? ● J/00K lua*symmetric ?not comforta,le to release it as 1.0 yet% hence it is not on luarocks" ● J/00K lua(osix L3.2." ?<nstall it 2ith LuaRocks" ● J/00K Stack=racePlus !.1.2 ?Eou can install it simply ,y doing9 luarocks install stacktrace(lus" ● J/00K luacheck 0.8.0 ?<t can ,e installed using LuaRocks? ● J/00K Firestr 0.# ● J/00K lua*llu7 ?<nstall current master: luarocks install llu7...? &hat 2e achie7ed The entry ,arrier for Lua as an a((lication de7elopment language is no2 much lo2er: a sim(le% (o(ular ,uild system a one*sto( sho( re(ository a culture of code reuse )/nd those who donBt 2ant it can still do things the old hard 2ay8+ Fostering an ecosystem9 lessons learned 0.4.1 0.5.2 0.4 0.5.1 2.0.7 It takes time 0.3.2 0.5 2.0.4.1 2.0.6 2.0.8 2.0.10 0.2 0.3.1 0.4.3 2.0.1 2.0.4 2.0.7.1 2.0.12 2.1.1 0.10.10.3 0.4.2 0.6 1.0 1.0.1 2.02.0.2 2.0.3 2.0.5 2.0.9 2.0.11 2.0.13 2.1.02.12.1.2 2.2.0 2007 2008 2009 2010 2011 2012 2013 2014 2.22015 Eou may need to ?,ootstra(2007 2008? it 2009 2010 2011 2012 2013 2014 20 to get it oD the ground Identify your audience =hey are those 2ho are listening to you% listen ,ack! $e ,old and share control8 <tBs riskier% ,ut itBs the only 2ay to ,uild a team in FOSS 'Mar 2010 'Mar 2011 'Mar 2012 'Mar 2013 'Mar 2014 'Feb 2015 'Sep 2009 'Sep 2010 'Sep 2011 'Sep 2012 'Sep 2013 'Sep 2014 =hank you8 htt(944luarocks.org .ontact: htt(944hisham.hm/ [email protected] @hisham_hm /,out these slides Feel free to share this presentation and to use parts of it in your o2n material Licensed under the Creati7e Commons CC BY 4.0: htt(s:/4creati7ecommons.org4licenses4,y44.0/ $onus slide * future ideas )Olua2sho("M+ E1tensi,le rockspecs: luarocks.addon.youraddon Using9 using={"foo"} loads luarocks.addon.foo Lots of details to decide% ,ut no2 LuaRocks can u(grade itself so 2e can e7olve the rockspec_format =he future could look like this: rockspec_format = "3.0" using = { "build_dependencies", -- adds support for build-only dependencies "busted", -- ensures Busted is installed, runs tests "ldoc", -- generates docs using LDoc "build.ext >= 2.0", -- example build type extending builtin } build_dependencies = { "bin2c >= 1.2" } build = { type = "ext", modules = { ["foo"] = { language = "c99", sources = "foo.c" } }, } doc = { --[[ ldoc specific flags ]] }.