├── site ├── www │ ├── bin │ │ └── .gitignore │ ├── favicon.ico │ ├── img │ │ ├── number_font.png │ │ └── tutorial-1.png │ ├── style │ │ ├── D3Craftism.ttf │ │ ├── images │ │ │ ├── small_title.png │ │ │ └── tetris_title.png │ │ └── Tupfile │ ├── .gitignore │ └── js │ │ └── Tupfile ├── .gitignore ├── Tuprules.tup ├── templates │ ├── tutorial.html │ └── index.html ├── leader.md ├── site.moon ├── changelog.moon ├── main.coffee ├── background.coffee ├── feed.moon ├── index.html ├── index.md └── js_reference.moon ├── .gitignore ├── nacl ├── game │ ├── main.lua │ ├── hi.png │ ├── start.ogg │ ├── theme.ogg │ └── tiles.png ├── js │ └── Tupfile ├── examples │ ├── cool.lua │ ├── boundary.lua │ ├── rectangle.lua │ ├── texture.lua │ ├── rotate.lua │ ├── font.lua │ ├── image_font.lua │ ├── audio.lua │ ├── input.lua │ ├── stack.lua │ ├── blit.lua │ ├── stress.lua │ └── loading.lua ├── aroma.nmf ├── lua-cjson-2.1.0 │ ├── Tupfile │ ├── THANKS │ ├── lua │ │ ├── json2lua.lua │ │ └── lua2json.lua │ ├── fpconv.h │ ├── LICENSE │ ├── lua-cjson-2.1.0-1.rockspec │ ├── dtoa_config.h │ ├── runtests.sh │ ├── lua-cjson.spec │ ├── g_fmt.c │ ├── Makefile │ └── strbuf.h ├── lua-5.1.5 │ ├── src │ │ ├── lapi.h │ │ ├── Tupfile │ │ ├── linit.c │ │ ├── lstring.h │ │ ├── lundump.h │ │ ├── ldebug.h │ │ ├── ltm.h │ │ ├── lfunc.h │ │ ├── lualib.h │ │ ├── lvm.h │ │ ├── ltable.h │ │ ├── lmem.h │ │ ├── lzio.h │ │ ├── ltm.c │ │ ├── lzio.c │ │ ├── ldo.h │ │ ├── llex.h │ │ ├── lmem.c │ │ ├── lparser.h │ │ ├── llimits.h │ │ ├── lcode.h │ │ ├── lopcodes.c │ │ ├── lstring.c │ │ ├── lgc.h │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── luac.c │ │ ├── lundump.c │ │ └── lstate.h │ ├── README │ ├── COPYRIGHT │ └── Makefile ├── installs_deps.sh ├── Tupfile ├── package.sh ├── Makefile └── index.html ├── examples └── tetris │ ├── .gitignore │ ├── Tupfile │ ├── back.png │ ├── logo.png │ ├── conf.moon │ └── index.html ├── src ├── nacl │ ├── nacl_audio.cpp │ ├── Tupfile │ ├── nacl_audio.h │ ├── gl.h │ ├── nacl_time.h │ ├── aroma.h │ ├── nacl_time.cpp │ ├── gl_context.h │ └── gl_context.cpp ├── lib │ ├── Tupfile │ └── renderer_support.moon ├── simplex.h ├── audio.cpp ├── tiles.cpp ├── audio.h ├── tiles.h ├── Tupfile ├── framebuffer.h ├── input.h ├── mesh.h ├── matrix.h ├── shader.h ├── context.h ├── lua_binding.h ├── aroma.cpp ├── font.h ├── geometry.h ├── common.h ├── image.h ├── canvas.h ├── context.cpp ├── simplex.cpp ├── input.cpp ├── renderer.h ├── lua_binding.cpp ├── framebuffer.cpp ├── matrix.cpp └── shader.cpp ├── tup.config ├── lib ├── mult.moon ├── ply2h.lua └── ply.lua ├── Tuprules.tup ├── README.md └── LICENSE.md /site/www/bin/.gitignore: -------------------------------------------------------------------------------- 1 | *.zip -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.so 2 | *.nexe 3 | core 4 | -------------------------------------------------------------------------------- /site/.gitignore: -------------------------------------------------------------------------------- 1 | .sitegen_cache 2 | www/examples -------------------------------------------------------------------------------- /site/Tuprules.tup: -------------------------------------------------------------------------------- 1 | site_root_dir = $(TUP_CWD) 2 | -------------------------------------------------------------------------------- /nacl/game/main.lua: -------------------------------------------------------------------------------- 1 | 2 | print "hello from main!" 3 | 4 | -------------------------------------------------------------------------------- /examples/tetris/.gitignore: -------------------------------------------------------------------------------- 1 | *.nexe 2 | *.nmf 3 | *.lua 4 | js 5 | -------------------------------------------------------------------------------- /examples/tetris/Tupfile: -------------------------------------------------------------------------------- 1 | 2 | : foreach *.moon |> moonc %f |> %B.lua 3 | -------------------------------------------------------------------------------- /nacl/game/hi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/nacl/game/hi.png -------------------------------------------------------------------------------- /nacl/js/Tupfile: -------------------------------------------------------------------------------- 1 | .gitignore 2 | 3 | : foreach *.coffee |> coffee -c %f |> %B.js 4 | -------------------------------------------------------------------------------- /nacl/game/start.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/nacl/game/start.ogg -------------------------------------------------------------------------------- /nacl/game/theme.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/nacl/game/theme.ogg -------------------------------------------------------------------------------- /nacl/game/tiles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/nacl/game/tiles.png -------------------------------------------------------------------------------- /site/www/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/site/www/favicon.ico -------------------------------------------------------------------------------- /examples/tetris/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/examples/tetris/back.png -------------------------------------------------------------------------------- /examples/tetris/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/examples/tetris/logo.png -------------------------------------------------------------------------------- /examples/tetris/conf.moon: -------------------------------------------------------------------------------- 1 | 2 | love.conf = => 3 | @screen.width = 300 4 | @screen.height = 400 5 | -------------------------------------------------------------------------------- /src/nacl/nacl_audio.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "nacl/nacl_audio.h" 3 | 4 | namespace aroma { 5 | } 6 | 7 | -------------------------------------------------------------------------------- /site/templates/tutorial.html: -------------------------------------------------------------------------------- 1 | $wrap{"index.html"} 2 |
3 | $body 4 |
5 | 6 | -------------------------------------------------------------------------------- /site/www/img/number_font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/site/www/img/number_font.png -------------------------------------------------------------------------------- /site/www/img/tutorial-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/site/www/img/tutorial-1.png -------------------------------------------------------------------------------- /site/www/style/D3Craftism.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/site/www/style/D3Craftism.ttf -------------------------------------------------------------------------------- /nacl/examples/cool.lua: -------------------------------------------------------------------------------- 1 | print "hello" 2 | 3 | function aroma.focus(f) 4 | print("focus is: ", f) 5 | end 6 | 7 | -------------------------------------------------------------------------------- /site/www/.gitignore: -------------------------------------------------------------------------------- 1 | index.html 2 | tutorial.html 3 | reference.html 4 | js_reference.html 5 | changelog.html 6 | feed.xml -------------------------------------------------------------------------------- /site/www/js/Tupfile: -------------------------------------------------------------------------------- 1 | .gitignore 2 | include_rules 3 | 4 | : foreach $(site_root_dir)/*.coffee |> coffee -c -o . %f |> %B.js 5 | -------------------------------------------------------------------------------- /site/www/style/images/small_title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/site/www/style/images/small_title.png -------------------------------------------------------------------------------- /site/www/style/images/tetris_title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/github/aroma/master/site/www/style/images/tetris_title.png -------------------------------------------------------------------------------- /src/lib/Tupfile: -------------------------------------------------------------------------------- 1 | .gitignore 2 | 3 | : foreach *.moon |> moonc %f |> %B.lua 4 | : foreach *.lua |> xxd -i %f > %f.h |> %f.h 5 | 6 | -------------------------------------------------------------------------------- /src/simplex.h: -------------------------------------------------------------------------------- 1 | #ifndef SIMPLEX_H_ 2 | #define SIMPLEX_H_ 3 | 4 | double simplex2d(double s, double t); 5 | 6 | #endif /* SIMPLEX_H_ */ 7 | -------------------------------------------------------------------------------- /nacl/aroma.nmf: -------------------------------------------------------------------------------- 1 | { 2 | "program": { 3 | "x86-64": {"url": "aroma_x86_64.nexe"}, 4 | "x86-32": {"url": "aroma_i686.nexe"} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /site/www/style/Tupfile: -------------------------------------------------------------------------------- 1 | .gitignore 2 | include_rules 3 | 4 | : foreach $(site_root_dir)/*.less |> ^ plessc %o^ plessc -f=compressed %f %o |> %B.css 5 | -------------------------------------------------------------------------------- /src/nacl/Tupfile: -------------------------------------------------------------------------------- 1 | .gitignore 2 | include_rules 3 | 4 | ifeq (@(TARGET),nacl) 5 | 6 | : foreach *.cpp | $(lua_lib_dir)/nacl.lua.h |> !cc |> %B.o 7 | 8 | endif 9 | 10 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/Tupfile: -------------------------------------------------------------------------------- 1 | .gitignore 2 | include_rules 3 | 4 | ifeq (@(TARGET),nacl) 5 | 6 | cjson_files = fpconv.c lua_cjson.c strbuf.c 7 | 8 | : foreach $(cjson_files) |> !cc |> %B.o 9 | 10 | endif 11 | -------------------------------------------------------------------------------- /src/audio.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "audio.h" 3 | 4 | namespace aroma { 5 | const char* AudioModule::module_name() { 6 | return "audio"; 7 | } 8 | 9 | void AudioModule::bind_all(lua_State* l) { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/nacl/nacl_audio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include "audio.h" 5 | 6 | namespace aroma { 7 | class NaClAudioModule : public AudioModule { 8 | // nothing yet, maybe never 9 | }; 10 | } 11 | -------------------------------------------------------------------------------- /tup.config: -------------------------------------------------------------------------------- 1 | CONFIG_TARGET=nacl 2 | #CONFIG_TARGET=glfw 3 | 4 | CONFIG_NACL_TC=/home/leafo/nacl/nacl_sdk/pepper_21/toolchain/linux_x86_newlib 5 | CONFIG_NACL_ARCH=x86_64 6 | #CONFIG_NACL_ARCH=i686 7 | CONFIG_NACL_BIN_NAME=aroma 8 | -------------------------------------------------------------------------------- /nacl/examples/boundary.lua: -------------------------------------------------------------------------------- 1 | local g = aroma.graphics 2 | 3 | local x, t = 0, 0 4 | local img = nil 5 | 6 | function aroma.draw() 7 | if not img then 8 | img = g.newImage('game/hi.png') 9 | end 10 | g.draw(img, 10, 10) 11 | end 12 | -------------------------------------------------------------------------------- /nacl/examples/rectangle.lua: -------------------------------------------------------------------------------- 1 | local g = aroma.graphics 2 | 3 | local x, t = 0, 0 4 | 5 | function aroma.update(dt) 6 | t = t + dt*3 7 | x = (math.sin(t) + 1)*100 8 | end 9 | 10 | function aroma.draw() 11 | g.rectangle(x,x,100,100) 12 | end 13 | 14 | -------------------------------------------------------------------------------- /src/tiles.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "tiles.h" 3 | 4 | namespace aroma { 5 | Tiled::Tiled(Image i, int tw, int th, int count) : 6 | image(i), tw(tw), th(th), count(count) 7 | { 8 | } 9 | 10 | void Tiled::draw_tile(int x, int y, int i) { 11 | } 12 | 13 | } 14 | 15 | -------------------------------------------------------------------------------- /nacl/examples/texture.lua: -------------------------------------------------------------------------------- 1 | local g = aroma.graphics 2 | 3 | local x, t = 0, 0 4 | local tex = g.newImage('game/hi.png') 5 | 6 | function aroma.update(dt) 7 | t = t + dt*3 8 | x = (math.sin(t) + 1)*100 9 | end 10 | 11 | function aroma.draw() 12 | g.draw(tex, x,x) 13 | end 14 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/THANKS: -------------------------------------------------------------------------------- 1 | The following people have helped with bug reports, testing and/or 2 | suggestions: 3 | 4 | - Louis-Philippe Perron (@loopole) 5 | - Ondřej Jirman 6 | - Steve Donovan 7 | - Zhang "agentzh" Yichun 8 | 9 | Thanks! 10 | -------------------------------------------------------------------------------- /site/leader.md: -------------------------------------------------------------------------------- 1 | 2 | **Aroma** is game creation framework that targets [Chrome's Native 3 | Client][1]. It lets you create games in the [Lua][2] programming language that can 4 | be be distributed through the Chrome Web Store. 5 | 6 | [1]: https://developers.google.com/native-client/ 7 | [2]: http://www.lua.org 8 | -------------------------------------------------------------------------------- /nacl/examples/rotate.lua: -------------------------------------------------------------------------------- 1 | local g = aroma.graphics 2 | 3 | local r = 0 4 | local tex = g.newImage('game/hi.png') 5 | 6 | function aroma.update(dt) 7 | r = r + dt 8 | end 9 | 10 | function aroma.draw() 11 | local size = tex:getHeight() 12 | g.draw(tex, 100, 100, r, 0.5, 0.5, size/2, size/2) 13 | end 14 | 15 | -------------------------------------------------------------------------------- /src/audio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include "lua_binding.h" 5 | 6 | namespace aroma { 7 | class AudioModule : public Bindable { 8 | public: 9 | const char* module_name(); 10 | void bind_all(lua_State* l); 11 | }; 12 | 13 | struct AudioSource { 14 | virtual void play() = 0; 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /nacl/examples/font.lua: -------------------------------------------------------------------------------- 1 | 2 | local g = aroma.graphics 3 | local other_font = g.newFont("32px monospace") 4 | 5 | local t = aroma.timer 6 | 7 | function aroma.draw() 8 | g.print("hello world", 10, 10) 9 | g.setColor(255,128,128) 10 | g.print(other_font, "here is fps: " .. t.getFPS(), 10, 70) 11 | g.setColor(255,255,255) 12 | end 13 | 14 | -------------------------------------------------------------------------------- /src/nacl/gl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // opengl headers 4 | #include 5 | #include "ppapi/c/ppb_opengles2.h" 6 | #include "ppapi/cpp/graphics_3d_client.h" 7 | #include "ppapi/cpp/graphics_3d.h" 8 | #include "ppapi/gles2/gl2ext_ppapi.h" 9 | 10 | #include "ppapi/cpp/completion_callback.h" 11 | #include "ppapi/cpp/rect.h" 12 | // ~ 13 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.2.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | LUAI_FUNC void luaA_pushobject (lua_State *L, const TValue *o); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /site/site.moon: -------------------------------------------------------------------------------- 1 | require "sitegen" 2 | 3 | sitegen.create_site => 4 | disable "autoadd" 5 | 6 | @version = "0.0.3" 7 | 8 | deploy_to "leaf@leafo.net", "www/aroma/" 9 | 10 | feed "feed.moon", "feed.xml" 11 | add "index.html" 12 | add "tutorial.md" 13 | add "reference.moon" 14 | add "js_reference.moon" 15 | add "changelog.moon" 16 | 17 | -------------------------------------------------------------------------------- /src/tiles.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "common.h" 5 | #include "image.h" 6 | #include "geometry.h" 7 | 8 | namespace aroma { 9 | class Tiled { 10 | protected: 11 | Image image; 12 | int tw, th, count; 13 | 14 | public: 15 | Tiled(Image i, int tw, int th, int count); 16 | void draw_tile(int x, int y, int i); 17 | }; 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /nacl/examples/image_font.lua: -------------------------------------------------------------------------------- 1 | 2 | local font = aroma.graphics.newImageFont("game/font.png", 3 | [[ abcdefghijklmnopqrstuvwxyz-1234567890!.,:;'"?$&]]) 4 | 5 | aroma.graphics.setFont(font) 6 | 7 | function aroma.draw() 8 | aroma.graphics.print("hello world!", 10, 10) 9 | aroma.graphics.print([[ abcdefghijklmnopqrstuvwxyz-1234567890!.,:;'"?$&]], 10, 20) 10 | end 11 | -------------------------------------------------------------------------------- /nacl/installs_deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | function get_package() { 4 | URL=$1 5 | TAR=$(basename $URL) 6 | if [ ! -f "$TAR" ]; then 7 | wget -O "$TAR" "$URL" 8 | fi 9 | echo "Unpacking $TAR" 10 | tar -xzf $TAR 11 | } 12 | 13 | get_package http://www.lua.org/ftp/lua-5.1.5.tar.gz 14 | get_package http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz 15 | 16 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/lua/json2lua.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | -- usage: json2lua.lua [json_file] 4 | -- 5 | -- Eg: 6 | -- echo '[ "testing" ]' | ./json2lua.lua 7 | -- ./json2lua.lua test.json 8 | 9 | local json = require "cjson" 10 | local util = require "cjson.util" 11 | 12 | local json_text = util.file_load(arg[1]) 13 | local t = json.decode(json_text) 14 | print(util.serialise_value(t)) 15 | -------------------------------------------------------------------------------- /src/Tupfile: -------------------------------------------------------------------------------- 1 | .gitignore 2 | include_rules 3 | 4 | src_files = context.cpp font.cpp geometry.cpp image.cpp input.cpp lua_binding.cpp matrix.cpp renderer.cpp shader.cpp simplex.cpp tiles.cpp audio.cpp 5 | 6 | : foreach $(src_files) | $(lua_lib_dir)/renderer_support.lua.h |> !cpp |> %B.o {lib_o} 7 | 8 | ifeq (@(TARGET),glfw) 9 | : {lib_o} |> $(CPP) $(link) -o %o %f $(libs) |> aroma.so 10 | endif 11 | 12 | -------------------------------------------------------------------------------- /nacl/examples/audio.lua: -------------------------------------------------------------------------------- 1 | local a = aroma.audio 2 | 3 | local bg = a.newSource("game/theme.ogg", "streaming") 4 | local effect = a.newSource("game/start.ogg") 5 | 6 | bg:setLooping(true) 7 | bg:play() 8 | 9 | function aroma.keypressed(key) 10 | if key == " " then 11 | effect:play() 12 | elseif key == "q" then 13 | bg:stop() 14 | elseif key == "w" then 15 | bg:play() 16 | end 17 | end 18 | 19 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/Tupfile: -------------------------------------------------------------------------------- 1 | .gitignore 2 | include_rules 3 | 4 | ifeq (@(TARGET),nacl) 5 | 6 | lua_files = lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c loslib.c lparser.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c ltm.c lundump.c lvm.c lzio.c print.c 7 | 8 | : foreach $(lua_files) |> !cc |> %B.o 9 | 10 | endif 11 | -------------------------------------------------------------------------------- /site/changelog.moon: -------------------------------------------------------------------------------- 1 | 2 | discount = require "discount" 3 | feed = require "feed" 4 | 5 | set "title", "Changelog" 6 | set "link_to_home", true 7 | 8 | html -> 9 | div { 10 | class: "changelog" 11 | 12 | h2 "Changelog" 13 | for entry in *feed 14 | div { 15 | class: "release" 16 | id: "v" .. entry._release.version 17 | raw discount trim_leading_white entry.description 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/nacl/nacl_time.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include "lua_binding.h" 5 | #include "renderer.h" 6 | 7 | namespace aroma { 8 | class NaClTimeModule : public Bindable { 9 | protected: 10 | Renderer* renderer; 11 | 12 | public: 13 | NaClTimeModule(Renderer* renderer); 14 | static int _getTime(lua_State* l); 15 | static int _getFPS(lua_State* l); 16 | 17 | const char* module_name(); 18 | void bind_all(lua_State* l); 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/lua/lua2json.lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | -- usage: lua2json.lua [lua_file] 4 | -- 5 | -- Eg: 6 | -- echo '{ "testing" }' | ./lua2json.lua 7 | -- ./lua2json.lua test.lua 8 | 9 | local json = require "cjson" 10 | local util = require "cjson.util" 11 | 12 | local env = { 13 | json = { null = json.null }, 14 | null = json.null 15 | } 16 | 17 | local t = util.run_script("data = " .. util.file_load(arg[1]), env) 18 | print(json.encode(t.data)) 19 | 20 | -- vi:ai et sw=4 ts=4: 21 | -------------------------------------------------------------------------------- /site/main.coffee: -------------------------------------------------------------------------------- 1 | 2 | log = (msg) -> console?.log msg 3 | 4 | track_event = (cat, action, label, value=0, interactive=true) -> 5 | log ["track event:", cat, action, label].join " " 6 | try 7 | _gaq.push ['_trackEvent', cat, action, label, value, interactive] 8 | catch e 9 | 10 | document.onclick = (e=window.event) -> 11 | elm = e.target 12 | while elm 13 | if match = elm.className?.match /event_(\w+)/ 14 | track_event "aroma", "click", match[1] 15 | break 16 | elm = elm.parentNode 17 | 18 | -------------------------------------------------------------------------------- /site/background.coffee: -------------------------------------------------------------------------------- 1 | 2 | set_background = (canvas) -> 3 | document.body.style.backgroundImage = "url(#{canvas.toDataURL()})" 4 | 5 | canvas = document.createElement "canvas" 6 | canvas.width = 32 7 | canvas.height = 32 8 | 9 | ctx = canvas.getContext "2d" 10 | ctx.fillStyle = "#F1F1F1" 11 | 12 | ctx.fillRect 0,0, 32,32 13 | 14 | ctx.save() 15 | 16 | ctx.translate 16, 16 17 | ctx.rotate Math.PI/4 18 | ctx.scale 12,12 19 | 20 | ctx.fillStyle = "#E3E3E3" 21 | ctx.fillRect -1, -1, 2, 2 22 | 23 | ctx.restore() 24 | 25 | setTimeout (-> set_background canvas), 0 26 | 27 | -------------------------------------------------------------------------------- /nacl/Tupfile: -------------------------------------------------------------------------------- 1 | .gitignore 2 | include_rules 3 | 4 | ifeq (@(TARGET),nacl) 5 | 6 | o_files = $(root_dir)/src/*.o $(root_dir)/src/nacl/*.o lua-5.1.5/src/*.o lua-cjson-2.1.0/*.o 7 | : $(o_files) |> !bin |> @(NACL_BIN_NAME)_@(NACL_ARCH).nexe 8 | 9 | # # generate manifest file for glibc 10 | # create_nmf = python2 @(NACL_TC)/../../tools/create_nmf.py 11 | # 12 | # nmf_args = -D $(OBJDUMP) 13 | # nmf_paths = -L @(NACL_TC)/x86_64-nacl/lib32 -L @(NACL_TC)/x86_64-nacl/lib 14 | # 15 | # : *.nexe |> $(create_nmf) $(nmf_args) -s . -o %o $(nmf_paths) %f |> aroma.nmf 16 | 17 | endif 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /nacl/package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Packages the nexes, nmf js, readme, and license into a zip 4 | 5 | OUT_DIR="tmp/aroma" 6 | TMP_DIR=$(dirname $OUT_DIR) 7 | 8 | VERSION=0.0.3 9 | 10 | mkdir -p $OUT_DIR 11 | 12 | make 64 13 | cp *.nexe $OUT_DIR 14 | 15 | make 32 16 | cp *.nexe $OUT_DIR 17 | 18 | cp *.nmf $OUT_DIR 19 | 20 | mkdir $OUT_DIR/js 21 | cp js/*.js $OUT_DIR/js 22 | 23 | cp ../README.md $OUT_DIR/README.txt 24 | cp ../LICENSE.md $OUT_DIR/LICENSE.txt 25 | 26 | ( 27 | cd $TMP_DIR 28 | apack "aroma-$VERSION.zip" aroma/ 29 | mv *.zip ../ 30 | ) 31 | 32 | rm -rf $TMP_DIR 33 | 34 | -------------------------------------------------------------------------------- /nacl/examples/input.lua: -------------------------------------------------------------------------------- 1 | print "Click to focus, arrow keys move" 2 | local g = aroma.graphics 3 | local k = aroma.keyboard 4 | 5 | local x, y = 100, 100 6 | local speed = 200 7 | 8 | function aroma.keypressed(key) 9 | if key == " " then 10 | print "Hello world!" 11 | end 12 | end 13 | 14 | function aroma.update(dt) 15 | local dx = k.isDown"left" and -1 or k.isDown"right" and 1 or 0 16 | local dy = k.isDown"up" and -1 or k.isDown"down" and 1 or 0 17 | 18 | x = x + dx * speed * dt 19 | y = y + dy * speed * dt 20 | end 21 | 22 | function aroma.draw() 23 | g.rectangle(x,y, 50, 50) 24 | end 25 | -------------------------------------------------------------------------------- /src/framebuffer.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef FRAMEBUFFER_H_ 3 | #define FRAMEBUFFER_H_ 4 | 5 | #include "common.h" 6 | #include "image.h" 7 | 8 | namespace aroma { 9 | 10 | void register_Framebuffer(lua_State *l); 11 | 12 | class FrameBuffer { 13 | public: 14 | int width, height; 15 | Image tex; 16 | GLuint fbo; 17 | GLuint depth; 18 | 19 | static int _new(lua_State *l); 20 | static int _bind(lua_State *l); 21 | static int _release(lua_State *l); 22 | static int _render(lua_State *l); 23 | 24 | static int _draw(lua_State *l); 25 | static int _bindTex(lua_State *l); 26 | // draw the image 27 | }; 28 | 29 | } 30 | 31 | #endif -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/fpconv.h: -------------------------------------------------------------------------------- 1 | /* Lua CJSON floating point conversion routines */ 2 | 3 | /* Buffer required to store the largest string representation of a double. 4 | * 5 | * Longest double printed with %.14g is 21 characters long: 6 | * -1.7976931348623e+308 */ 7 | # define FPCONV_G_FMT_BUFSIZE 32 8 | 9 | #ifdef USE_INTERNAL_FPCONV 10 | static inline void fpconv_init() 11 | { 12 | /* Do nothing - not required */ 13 | } 14 | #else 15 | extern inline void fpconv_init(); 16 | #endif 17 | 18 | extern int fpconv_g_fmt(char*, double, int); 19 | extern double fpconv_strtod(const char*, char**); 20 | 21 | /* vi:ai et sw=4 ts=4: 22 | */ 23 | -------------------------------------------------------------------------------- /nacl/Makefile: -------------------------------------------------------------------------------- 1 | 2 | strip: 3 | ls *.nexe | while read name; do x86_64-nacl-strip $$name -o $$name; done 4 | 5 | deploy: 6 | rsync -rvuzLR *.html *.nexe *.nmf js/ game/ examples/ leaf@leafo.net:www/aroma/demo 7 | 8 | volcanox:: 9 | rsync -rvuzLR --exclude volcanox/.git volcanox/ leaf@leafo.net:www/aroma/ 10 | 11 | exoslime:: 12 | rsync -rvuzLR --exclude exoslime/.git exoslime/ leaf@leafo.net:www/aroma/ 13 | 14 | 64: 15 | tup upd # 64 bit build is default 16 | 17 | 32: 18 | echo "CONFIG_NACL_ARCH=i686" >> ../tup.config 19 | echo "CONFIG_NACL_BIN_NAME=aroma_tmp" >> ../tup.config 20 | tup upd 21 | mv aroma_tmp_i686.nexe aroma_i686.nexe 22 | git checkout -- ../tup.config 23 | 24 | 25 | -------------------------------------------------------------------------------- /lib/mult.moon: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env moon 2 | 3 | to_i = (size, x,y) -> y * size + x 4 | 5 | value = (left, right, x, y, size) -> 6 | idx = (...) -> to_i size, ... 7 | parts = for i = 0, size - 1 8 | table.concat { 9 | left, "[", idx(i, y), "] * ", right, "[", idx(x, i), "]" 10 | } 11 | 12 | table.concat parts, " + " 13 | 14 | generate = (left, right, size=4) -> 15 | parts = {} 16 | for y = 0, size - 1 17 | for x = 0, size - 1 18 | table.insert parts, value left, right, x, y, size 19 | table.concat parts, ",\n" 20 | 21 | 22 | left, right, size = ... 23 | if not left or not right or not size or not tonumber size 24 | print "usage: ./mult.moon left right size" 25 | return 26 | 27 | print generate left, right, tonumber size 28 | -------------------------------------------------------------------------------- /nacl/examples/stack.lua: -------------------------------------------------------------------------------- 1 | local g = aroma.graphics 2 | local s = 100 3 | 4 | function r() 5 | g.rectangle(0,0, s,s) 6 | end 7 | 8 | function flower() 9 | for i = 0, 2 do 10 | g.push() 11 | g.translate(s/2, s/2) 12 | g.rotate(i/10 * math.pi*2) 13 | g.translate(-s/2, -s/2) 14 | r() 15 | g.pop() 16 | end 17 | end 18 | 19 | function aroma.draw() 20 | g.setColor(128,255,128) 21 | r() 22 | 23 | g.setColor(255,128,255) 24 | g.push() 25 | g.translate(20, 20) 26 | r() 27 | g.pop() 28 | 29 | g.setColor(128,255,255) 30 | g.push() 31 | g.translate(10, 150) 32 | for i = 0, 5 do 33 | g.push() 34 | g.scale(0.3, 0.3) 35 | flower() 36 | g.pop() 37 | g.translate(50, 0) 38 | end 39 | g.pop() 40 | 41 | end 42 | -------------------------------------------------------------------------------- /src/nacl/aroma.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include "ppapi/cpp/instance.h" 7 | #include "ppapi/cpp/module.h" 8 | #include "ppapi/cpp/var.h" 9 | 10 | #include "ppapi/cpp/rect.h" 11 | 12 | #include "ppapi/cpp/input_event.h" 13 | 14 | extern "C" { 15 | #include "lua.h" 16 | #include "lualib.h" 17 | #include "lauxlib.h" 18 | } 19 | 20 | #include 21 | #include 22 | 23 | #include "common.h" 24 | 25 | using namespace std; 26 | 27 | extern "C" int luaopen_cjson(lua_State *l); 28 | 29 | namespace aroma { 30 | byte* decode_byte_string(const char* str, size_t str_len, size_t num_bytes); 31 | 32 | void push_var(lua_State* l, pp::Var var); 33 | pp::Var to_var(lua_State* l, int index); 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /nacl/examples/blit.lua: -------------------------------------------------------------------------------- 1 | local g = aroma.graphics 2 | local tex = g.newImage('game/hi.png') 3 | local r = 0 4 | 5 | -- split entire image into quads 6 | local count = 8 7 | local s = tex:getWidth() / count 8 | 9 | function q(x, y) 10 | return g.newQuad(x, y, s, s, tex:getWidth(), tex:getHeight()) 11 | end 12 | 13 | function xy(i) 14 | return (i - 1) % count * s, math.floor((i - 1) / count) * s 15 | end 16 | 17 | local quads = {} 18 | for i = 1, count^2 do 19 | table.insert(quads, q(xy(i))) 20 | end 21 | 22 | function aroma.update(dt) 23 | r = r + dt * 3 24 | end 25 | 26 | function aroma.draw() 27 | g.push() 28 | g.translate(20, 20) 29 | for i, q in ipairs(quads) do 30 | local x, y = xy(i) 31 | g.drawq(tex, q, x, y, r, 1, 1, s/2, s/2) 32 | end 33 | g.pop() 34 | end 35 | -------------------------------------------------------------------------------- /src/input.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include "lua_binding.h" 5 | 6 | #include 7 | 8 | using std::set; 9 | 10 | namespace aroma { 11 | class InputHandler : public Bindable { 12 | protected: 13 | LuaBinding* binding; 14 | void dispatch_key_event(const char* func, int key); 15 | char ascii_table[95][2]; 16 | set keys_down; 17 | 18 | public: 19 | const char* key_name(int key); 20 | 21 | InputHandler(LuaBinding* binding); 22 | 23 | void key_down(int key); 24 | void key_up(int key); 25 | 26 | bool is_key_down(const char* name); 27 | 28 | // mousedown, mouseup, mousemove, etc 29 | 30 | const char* module_name(); 31 | void bind_all(lua_State *l); 32 | 33 | static int _isDown(lua_State *l); 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /src/nacl/nacl_time.cpp: -------------------------------------------------------------------------------- 1 | #include "nacl/nacl_time.h" 2 | 3 | namespace aroma { 4 | 5 | NaClTimeModule::NaClTimeModule(Renderer* renderer) 6 | : renderer(renderer) { } 7 | 8 | // this can be generic 9 | int NaClTimeModule::_getTime(lua_State* l) { 10 | NaClTimeModule* time = upvalue_self(NaClTimeModule); 11 | lua_pushnumber(l, time->renderer->get_context()->get_time()); 12 | return 1; 13 | } 14 | 15 | int NaClTimeModule::_getFPS(lua_State* l) { 16 | NaClTimeModule* time = upvalue_self(NaClTimeModule); 17 | lua_pushnumber(l, time->renderer->get_fps()); 18 | return 1; 19 | } 20 | 21 | const char* NaClTimeModule::module_name() { 22 | return "timer"; 23 | } 24 | 25 | void NaClTimeModule::bind_all(lua_State* l) { 26 | set_new_func("getTime", _getTime); 27 | set_new_func("getFPS", _getFPS); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /nacl/examples/stress.lua: -------------------------------------------------------------------------------- 1 | local amount = 2000 2 | 3 | local g = aroma.graphics 4 | local img = g.newImage("game/tiles.png") 5 | 6 | local tw = 16 7 | local count = img:getWidth() / tw 8 | 9 | g.setBackgroundColor(200, 200, 200) 10 | 11 | local quads = {} 12 | function blit_tile(i, x, y) 13 | local q = quads[i] 14 | if not q then 15 | q = g.newQuad( 16 | tw * (i % count), 17 | math.floor(tw / count), 18 | tw, tw, 19 | img:getWidth(), img:getHeight()) 20 | 21 | quads[i] = q 22 | end 23 | 24 | g.drawq(img, q, x, y) 25 | end 26 | 27 | function aroma.draw() 28 | g.translate((g:getWidth()-tw)/2, (g:getHeight()-tw)/2) 29 | 30 | for k = 1, amount do 31 | local rad = math.sqrt(k) 32 | local d = rad*4 33 | blit_tile(k % 3, math.cos(rad)*d, math.sin(rad)*d) 34 | end 35 | end 36 | 37 | 38 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c,v 1.14.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Initialization of libraries for lua.c 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | #include "lua.h" 12 | 13 | #include "lualib.h" 14 | #include "lauxlib.h" 15 | 16 | 17 | static const luaL_Reg lualibs[] = { 18 | {"", luaopen_base}, 19 | {LUA_LOADLIBNAME, luaopen_package}, 20 | {LUA_TABLIBNAME, luaopen_table}, 21 | {LUA_IOLIBNAME, luaopen_io}, 22 | {LUA_OSLIBNAME, luaopen_os}, 23 | {LUA_STRLIBNAME, luaopen_string}, 24 | {LUA_MATHLIBNAME, luaopen_math}, 25 | {LUA_DBLIBNAME, luaopen_debug}, 26 | {NULL, NULL} 27 | }; 28 | 29 | 30 | LUALIB_API void luaL_openlibs (lua_State *L) { 31 | const luaL_Reg *lib = lualibs; 32 | for (; lib->func; lib++) { 33 | lua_pushcfunction(L, lib->func); 34 | lua_pushstring(L, lib->name); 35 | lua_call(L, 1, 0); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /src/nacl/gl_context.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "nacl/gl.h" 4 | #include "context.h" 5 | 6 | namespace aroma { 7 | class Renderer; 8 | 9 | class OpenGLContext : public pp::Graphics3DClient, public GLContext { 10 | protected: 11 | bool flushing; 12 | 13 | Renderer *renderer; 14 | const struct PPB_OpenGLES2* gles2_interface; 15 | pp::Instance *instance; 16 | pp::Graphics3D graphics; 17 | pp::Size size; 18 | 19 | public: 20 | OpenGLContext(pp::Instance* instance); 21 | virtual ~OpenGLContext(); 22 | void Graphics3DContextLost(); 23 | 24 | void set_renderer(Renderer *renderer); 25 | 26 | bool make_current(); 27 | // void resize(const pp::Size& s); 28 | void resize(const int w, const int h); 29 | void flush(); 30 | void render(); // tell the renderer to tick 31 | 32 | bool is_flushing(); 33 | 34 | int width(); 35 | int height(); 36 | double get_time(); 37 | }; 38 | } 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/lib/renderer_support.moon: -------------------------------------------------------------------------------- 1 | 2 | 3 | import graphics from aroma 4 | 5 | vert = [[ 6 | precision mediump float; 7 | 8 | uniform vec4 C; 9 | uniform mat4 PMatrix; 10 | uniform bool texturing; 11 | 12 | attribute vec2 P; // vertex 13 | attribute vec2 T; // texture coords 14 | 15 | varying lowp vec4 vColor; 16 | varying mediump vec2 vTex; 17 | 18 | void main(void) { 19 | if (texturing) vTex = T; 20 | vColor = C; 21 | gl_Position = PMatrix * vec4(P, 0.0, 1.0); 22 | } 23 | ]] 24 | 25 | frag = [[ 26 | precision mediump float; 27 | 28 | uniform sampler2D tex; 29 | uniform bool texturing; 30 | 31 | varying lowp vec4 vColor; 32 | varying mediump vec2 vTex; 33 | 34 | void main(void) { 35 | if (texturing) { 36 | gl_FragColor = texture2D(tex, vTex) * vColor; 37 | } else { 38 | gl_FragColor = vColor; 39 | } 40 | } 41 | ]] 42 | 43 | graphics.setDefaultShader graphics.newShader vert, frag 44 | 45 | -------------------------------------------------------------------------------- /src/mesh.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef MESH_H_ 3 | #define MESH_H_ 4 | 5 | #include "geometry.h" 6 | 7 | namespace aroma { 8 | 9 | void register_Mesh(lua_State *l); 10 | 11 | /** 12 | * a 2d or 3d mesh to be rendered as vertex array 13 | */ 14 | class Mesh { 15 | int dim, count; 16 | double *vertexArray; 17 | double *normalArray; 18 | GLenum format; 19 | public: 20 | static int _new(lua_State *l); 21 | 22 | static int _render(lua_State *l); 23 | static int _setNormals(lua_State *l); 24 | static int _dump(lua_State *l); 25 | 26 | static int _vertices(lua_State *l); // vertex iterator 27 | static int _verticesIter(lua_State *l); 28 | 29 | 30 | static int _count(lua_State *l); 31 | static int _dim(lua_State *l); 32 | 33 | static int _set(lua_State *l); 34 | static int _get(lua_State *l); // get a vertex 35 | 36 | static int _clone(lua_State *l); 37 | static int _gc(lua_State *l); // garbage collect 38 | }; 39 | 40 | } 41 | 42 | #endif /* MESH_H_ */ 43 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h,v 1.43.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | 11 | #include "lgc.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | 15 | 16 | #define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) 17 | 18 | #define sizeudata(u) (sizeof(union Udata)+(u)->len) 19 | 20 | #define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) 21 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 22 | (sizeof(s)/sizeof(char))-1)) 23 | 24 | #define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) 25 | 26 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 27 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); 28 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /nacl/examples/loading.lua: -------------------------------------------------------------------------------- 1 | local g = aroma.graphics 2 | local audio = aroma.audio 3 | 4 | local start = aroma.timer.getTime() 5 | 6 | nacl.prefetch { 7 | "game/world.lua", 8 | "game/main.lua", 9 | "game/another.lua", 10 | image = { 11 | "game/hi.png", 12 | "game/tiles.png" 13 | }, 14 | sound = { 15 | "volcanox/sound/start.wav", 16 | "volcanox/sound/hit_me.wav" 17 | }, 18 | music = { 19 | "volcanox/sound/theme.ogg" 20 | } 21 | } 22 | 23 | require "game.world" 24 | require "game.world" 25 | require "game.main" 26 | require "game.another" 27 | 28 | local i1 = g.newImage"game/hi.png" 29 | local i2 = g.newImage"game/tiles.png" 30 | 31 | local a_bg = audio.newSource "volcanox/sound/theme.ogg" 32 | local a_start = audio.newSource "volcanox/sound/start.wav", "static" 33 | local a_hit_me = audio.newSource "volcanox/sound/hit_me.wav", "static" 34 | 35 | print(aroma.timer.getTime() - start) 36 | 37 | function aroma.draw() 38 | g.draw(i1, 10, 10) 39 | end 40 | -------------------------------------------------------------------------------- /src/matrix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | #include 5 | 6 | using std::stack; 7 | 8 | namespace aroma { 9 | class Shader; 10 | 11 | struct Mat4 { 12 | GLfloat data[16]; 13 | 14 | Mat4 operator*(const Mat4 & other) const; 15 | 16 | void print(); 17 | 18 | static Mat4 identity(); 19 | static Mat4 ortho2d(float left, float right, float top, float bottom); 20 | static Mat4 scale(float sx=1, float sy=1, float sz=1); 21 | static Mat4 translate(float tx=0, float ty=0, float tz=0); 22 | static Mat4 rotate2d(float d); 23 | }; 24 | 25 | class MatrixStack { 26 | protected: 27 | typedef stack mstack; 28 | mstack matrices; 29 | 30 | public: 31 | MatrixStack(); 32 | 33 | void reset(Mat4 mat); 34 | void push(Mat4 mat); 35 | void push(); 36 | void set(Mat4 mat); 37 | void mul(Mat4 mat); 38 | 39 | void pop(); 40 | Mat4 current(); 41 | 42 | void apply(Shader *shader, const char* name = "PMatrix"); 43 | }; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/shader.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "common.h" 5 | #include "matrix.h" 6 | #include "geometry.h" 7 | 8 | namespace aroma { 9 | 10 | void register_Shader(lua_State *l); 11 | 12 | class Shader { 13 | public: 14 | bool linked; 15 | GLuint program; 16 | 17 | Shader(); 18 | bool add(GLuint type, const char *src); 19 | bool link(); 20 | void bind(); 21 | 22 | GLuint attr_loc(const char* name); 23 | GLuint uniform_loc(const char* name); 24 | 25 | void set_uniform(const char* name, const Mat4 & matrix); 26 | void set_uniform(const char* name, const Color & color); 27 | void set_uniform(const char* name, const float num); 28 | void set_uniform(const char* name, const GLuint num); 29 | 30 | static int _new(lua_State *l); 31 | static int _gc(lua_State *l); 32 | 33 | static int _bind(lua_State *l); 34 | static int _release(lua_State *l); 35 | static int _uniform(lua_State *l); 36 | 37 | static int _frag(lua_State *l); 38 | static int _vert(lua_State *l); 39 | }; 40 | 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/context.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace aroma { 4 | class Renderer; 5 | 6 | class GLContext { 7 | public: 8 | virtual bool make_current() = 0; 9 | virtual void resize(const int w, const int h) = 0; 10 | virtual void flush() = 0; 11 | // virtual void render(); // tell the renderer to tick 12 | 13 | virtual int width() = 0; 14 | virtual int height() = 0; 15 | 16 | virtual double get_time() = 0; 17 | 18 | virtual void set_renderer(Renderer *r) { } 19 | virtual bool is_flushing() = 0; 20 | }; 21 | 22 | #ifndef AROMA_NACL 23 | 24 | class GLFWContext : public GLContext { 25 | protected: 26 | bool created; 27 | int w; 28 | int h; 29 | const char* title; 30 | 31 | bool make_window(); 32 | 33 | public: 34 | GLFWContext(int w, int h, const char* title); 35 | 36 | bool make_current(); 37 | void resize(const int w, const int h); 38 | void flush(); 39 | 40 | int width(); 41 | int height(); 42 | double get_time(); 43 | 44 | bool is_flushing(); 45 | }; 46 | 47 | #endif 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | /* load one chunk; from lundump.c */ 14 | LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name); 15 | 16 | /* make header; from lundump.c */ 17 | LUAI_FUNC void luaU_header (char* h); 18 | 19 | /* dump one chunk; from ldump.c */ 20 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip); 21 | 22 | #ifdef luac_c 23 | /* print one chunk; from print.c */ 24 | LUAI_FUNC void luaU_print (const Proto* f, int full); 25 | #endif 26 | 27 | /* for header of binary files -- this is Lua 5.1 */ 28 | #define LUAC_VERSION 0x51 29 | 30 | /* for header of binary files -- this is the official format */ 31 | #define LUAC_FORMAT 0 32 | 33 | /* size of header of binary files */ 34 | #define LUAC_HEADERSIZE 12 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/lua_binding.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.h" 4 | 5 | namespace aroma { 6 | class Bindable { 7 | public: 8 | virtual const char* module_name() = 0; 9 | virtual void bind_all(lua_State* l) = 0; 10 | }; 11 | 12 | class LuaBinding { 13 | protected: 14 | lua_State* l; 15 | lua_State* game_thread; 16 | void preload_library(const char* name); 17 | virtual void handle_error(lua_State *thread, const char* name); 18 | 19 | public: 20 | LuaBinding(); 21 | lua_State* lua(); 22 | 23 | virtual void bind_module(Bindable *b); 24 | virtual bool bind_all(); // set up the lua env 25 | 26 | bool is_type(lua_State* l, int i, const char* type); 27 | void store_in_registry(lua_State *l, int i, const char* name); 28 | int from_registry(lua_State *l, const char* name); 29 | 30 | void set_game_thread(lua_State* thread); 31 | 32 | // pops nargs from top and send event to name on game_thread 33 | void send_event(const char* name, int nargs); 34 | 35 | bool load_and_run(void* buffer, size_t buff_len, const char* name); 36 | void push_self(); 37 | }; 38 | 39 | void stack_dump(lua_State *L); 40 | } 41 | 42 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2012 Mark Pulford 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h,v 2.3.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1) 15 | 16 | #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) 17 | 18 | #define resethookcount(L) (L->hookcount = L->basehookcount) 19 | 20 | 21 | LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o, 22 | const char *opname); 23 | LUAI_FUNC void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 24 | LUAI_FUNC void luaG_aritherror (lua_State *L, const TValue *p1, 25 | const TValue *p2); 26 | LUAI_FUNC int luaG_ordererror (lua_State *L, const TValue *p1, 27 | const TValue *p2); 28 | LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...); 29 | LUAI_FUNC void luaG_errormsg (lua_State *L); 30 | LUAI_FUNC int luaG_checkcode (const Proto *pt); 31 | LUAI_FUNC int luaG_checkopenop (Instruction i); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h,v 2.6.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_EQ, /* last tag method with `fast' access */ 24 | TM_ADD, 25 | TM_SUB, 26 | TM_MUL, 27 | TM_DIV, 28 | TM_MOD, 29 | TM_POW, 30 | TM_UNM, 31 | TM_LEN, 32 | TM_LT, 33 | TM_LE, 34 | TM_CONCAT, 35 | TM_CALL, 36 | TM_N /* number of elements in the enum */ 37 | } TMS; 38 | 39 | 40 | 41 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 42 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 43 | 44 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 45 | 46 | LUAI_DATA const char *const luaT_typenames[]; 47 | 48 | 49 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 50 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 51 | TMS event); 52 | LUAI_FUNC void luaT_init (lua_State *L); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h,v 2.4.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 | cast(int, sizeof(TValue)*((n)-1))) 16 | 17 | #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 | cast(int, sizeof(TValue *)*((n)-1))) 19 | 20 | 21 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 22 | LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); 23 | LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); 24 | LUAI_FUNC UpVal *luaF_newupval (lua_State *L); 25 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 26 | LUAI_FUNC void luaF_close (lua_State *L, StkId level); 27 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 28 | LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); 29 | LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); 30 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 31 | int pc); 32 | 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* Key to file-handle type */ 15 | #define LUA_FILEHANDLE "FILE*" 16 | 17 | 18 | #define LUA_COLIBNAME "coroutine" 19 | LUALIB_API int (luaopen_base) (lua_State *L); 20 | 21 | #define LUA_TABLIBNAME "table" 22 | LUALIB_API int (luaopen_table) (lua_State *L); 23 | 24 | #define LUA_IOLIBNAME "io" 25 | LUALIB_API int (luaopen_io) (lua_State *L); 26 | 27 | #define LUA_OSLIBNAME "os" 28 | LUALIB_API int (luaopen_os) (lua_State *L); 29 | 30 | #define LUA_STRLIBNAME "string" 31 | LUALIB_API int (luaopen_string) (lua_State *L); 32 | 33 | #define LUA_MATHLIBNAME "math" 34 | LUALIB_API int (luaopen_math) (lua_State *L); 35 | 36 | #define LUA_DBLIBNAME "debug" 37 | LUALIB_API int (luaopen_debug) (lua_State *L); 38 | 39 | #define LUA_LOADLIBNAME "package" 40 | LUALIB_API int (luaopen_package) (lua_State *L); 41 | 42 | 43 | /* open all previous libraries */ 44 | LUALIB_API void (luaL_openlibs) (lua_State *L); 45 | 46 | 47 | 48 | #ifndef lua_assert 49 | #define lua_assert(x) ((void)0) 50 | #endif 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /lib/ply2h.lua: -------------------------------------------------------------------------------- 1 | 2 | require "ply" 3 | require "cosmo" 4 | 5 | function ply2h(fname) 6 | local mesh = ply.parse(fname) 7 | local vs = mesh:getVertices(); 8 | local ns = mesh:getNormals(); 9 | 10 | local count = #vs 11 | 12 | local name, ext = fname:match"^(.*)%.(%w*)$" 13 | 14 | local function list_formatter(list) 15 | local count = #list 16 | local row_length = 6 17 | return function() 18 | for i,entry in ipairs(list) do 19 | cosmo.yield{ 20 | v = string.format("% f", entry), 21 | newline = i % row_length == 0 and "\n\t" or "", 22 | _template = i == count and 2 or 1 23 | } 24 | end 25 | end 26 | end 27 | 28 | 29 | 30 | return cosmo.f[==[ 31 | #ifndef $name 32 | #define $name 33 | 34 | double $vname[] = { 35 | $vertices[[$v, $newline]],[[$v]] 36 | }; 37 | 38 | double $vname_normal[] = { 39 | $normals[[$v, $newline]],[[$v]] 40 | }; 41 | 42 | 43 | int $vname_len = $count; 44 | 45 | #endif /* $name */ 46 | ]==]{ 47 | name = string.upper(name).."_PLY_H_", 48 | count = count, 49 | 50 | vname = name.."_"..ext, 51 | vname_len = name.."_"..ext.."_len", 52 | vertices = list_formatter(vs), 53 | 54 | 55 | vname_normal = name.."_normals_"..ext, 56 | normals = list_formatter(ns) 57 | } 58 | end 59 | 60 | print(ply2h(...)) 61 | 62 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h,v 2.5.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o))) 17 | 18 | #define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \ 19 | (((o) = luaV_tonumber(o,n)) != NULL)) 20 | 21 | #define equalobj(L,o1,o2) \ 22 | (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) 23 | 24 | 25 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 26 | LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); 27 | LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); 28 | LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); 29 | LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key, 30 | StkId val); 31 | LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key, 32 | StkId val); 33 | LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); 34 | LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h,v 2.10.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gkey(n) (&(n)->i_key.nk) 15 | #define gval(n) (&(n)->i_val) 16 | #define gnext(n) ((n)->i_key.nk.next) 17 | 18 | #define key2tval(n) (&(n)->i_key.tvk) 19 | 20 | 21 | LUAI_FUNC const TValue *luaH_getnum (Table *t, int key); 22 | LUAI_FUNC TValue *luaH_setnum (lua_State *L, Table *t, int key); 23 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 24 | LUAI_FUNC TValue *luaH_setstr (lua_State *L, Table *t, TString *key); 25 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 26 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 27 | LUAI_FUNC Table *luaH_new (lua_State *L, int narray, int lnhash); 28 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, int nasize); 29 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 30 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 31 | LUAI_FUNC int luaH_getn (Table *t); 32 | 33 | 34 | #if defined(LUA_DEBUG) 35 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 36 | LUAI_FUNC int luaH_isdummy (Node *n); 37 | #endif 38 | 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /Tuprules.tup: -------------------------------------------------------------------------------- 1 | 2 | !cpp = |> ^ g++ %f^ $(CPP) $(flags) $(cpp_flags) -c %f |> 3 | !cc = |> ^ gcc %f^ $(CC) $(flags) -c %f |> 4 | !bin = |> $(CPP) %f $(link) $(libs) -o %o |> 5 | 6 | root_dir = $(TUP_CWD) 7 | lua_lib_dir = $(TUP_CWD)/src/lib 8 | 9 | flags += -I$(TUP_CWD)/src 10 | 11 | # flags += -O2 12 | # link += -O2 13 | 14 | ifeq (@(TARGET),nacl) 15 | # TODO fix platform specific stuff 16 | nacl_bin = @(NACL_TC)/x86_64-nacl/bin 17 | 18 | CC = $(nacl_bin)/gcc 19 | CPP = $(nacl_bin)/g++ 20 | OBJDUMP = $(nacl_bin)/objdump 21 | 22 | flags += -Wno-long-long -Wall 23 | flags += -I$(TUP_CWD)/nacl/lua-5.1.5/src 24 | flags += -I$(TUP_CWD)/nacl/lua-cjson-2.1.0 25 | 26 | flags += -DAROMA_NACL 27 | flags += -pthread 28 | 29 | cpp_flags += -std=gnu++98 30 | 31 | link += -lppapi_gles2 -lppapi_cpp -lppapi -lnosys 32 | 33 | ifeq (@(NACL_ARCH),x86_64) 34 | flags += -m64 35 | link += -m64 36 | else 37 | flags += -m32 38 | link += -m32 39 | endif 40 | 41 | endif 42 | 43 | ifeq (@(TARGET),glfw) 44 | CC = g++ 45 | libs = -lglfw 46 | 47 | flags += -fpic 48 | 49 | ifeq (@(TUP_PLATFORM),linux) 50 | libs += -lGLU -lGL -lX11 -lXrandr -lm -lcorona -ldl 51 | link = -fpic -shared 52 | endif 53 | 54 | ifeq (@(TUP_PLATFORM),macosx) 55 | libs += -framework ApplicationServices -framework OpenGL -framework Cocoa -L/usr/X11/lib/ 56 | flags += -I/usr/X11/include/ 57 | link = -bundle -undefined dynamic_lookup 58 | endif 59 | 60 | endif 61 | 62 | 63 | # flags += -g 64 | # libs += -g 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/README: -------------------------------------------------------------------------------- 1 | README for Lua 5.1 2 | 3 | See INSTALL for installation instructions. 4 | See HISTORY for a summary of changes since the last released version. 5 | 6 | * What is Lua? 7 | ------------ 8 | Lua is a powerful, light-weight programming language designed for extending 9 | applications. Lua is also frequently used as a general-purpose, stand-alone 10 | language. Lua is free software. 11 | 12 | For complete information, visit Lua's web site at http://www.lua.org/ . 13 | For an executive summary, see http://www.lua.org/about.html . 14 | 15 | Lua has been used in many different projects around the world. 16 | For a short list, see http://www.lua.org/uses.html . 17 | 18 | * Availability 19 | ------------ 20 | Lua is freely available for both academic and commercial purposes. 21 | See COPYRIGHT and http://www.lua.org/license.html for details. 22 | Lua can be downloaded at http://www.lua.org/download.html . 23 | 24 | * Installation 25 | ------------ 26 | Lua is implemented in pure ANSI C, and compiles unmodified in all known 27 | platforms that have an ANSI C compiler. In most Unix-like platforms, simply 28 | do "make" with a suitable target. See INSTALL for detailed instructions. 29 | 30 | * Origin 31 | ------ 32 | Lua is developed at Lua.org, a laboratory of the Department of Computer 33 | Science of PUC-Rio (the Pontifical Catholic University of Rio de Janeiro 34 | in Brazil). 35 | For more information about the authors, see http://www.lua.org/authors.html . 36 | 37 | (end of README) 38 | -------------------------------------------------------------------------------- /site/feed.moon: -------------------------------------------------------------------------------- 1 | require "date" 2 | 3 | release = (t) -> 4 | title = "version "..t.version 5 | desc = if t.changes 6 | leading = t.changes\match"^(%s*)" or "" 7 | simple_date = t.date\fmt "%B %d %Y" 8 | table.concat { 9 | leading .. "## ".. title .. " - " .. simple_date 10 | "\n\n" 11 | t.changes 12 | } 13 | else 14 | "" 15 | { 16 | title: title 17 | link: "http://leafo.net/aroma/#v" .. t.version 18 | date: t.date 19 | description: desc 20 | _release: t 21 | } 22 | 23 | return { 24 | format: "markdown" 25 | title: "Aroma Changelog" 26 | link: "http://leafo.net/aroma/" 27 | description: "Aroma is a game engine for Native Client" 28 | 29 | release { 30 | version: "0.0.3" 31 | date: date 2012, 9, 3, 13, 06 32 | changes: [[ 33 | * updated to Pepper 21 34 | * throw error when module can't be found 35 | * `module` and `package.seeall` work within the async scope instead of the global one 36 | * added `aroma.graphics.setLineWidth`, `Quad:flip`, `aroma.graphics.newImageFont` 37 | * `aroma.graphics.print` can now take a transformation 38 | ]] 39 | } 40 | 41 | release { 42 | version: "0.0.2" 43 | date: date 2012, 5, 14, 11, 23 44 | changes: [[ 45 | * fixed broken default loader 46 | * unload all modules that have been required on `execute` 47 | ]] 48 | } 49 | 50 | release { 51 | version: "0.0.1" 52 | date: date 2012, 5, 13, 18, 53 53 | changes: [[ 54 | Initial Release 55 | ]] 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/aroma.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "canvas.h" 3 | #include "image.h" 4 | 5 | using namespace aroma; 6 | 7 | namespace aroma { 8 | const char *aroma_current_dir; 9 | } 10 | 11 | static const struct luaL_Reg aroma_funcs [] = { 12 | {"new", Canvas::_new}, 13 | // {"image_bytes", Image::_get_image_bytes}, 14 | {NULL, NULL} 15 | }; 16 | 17 | extern "C" { 18 | LUALIB_API int luaopen_aroma(lua_State *l) { 19 | aroma_current_dir = getcwd(NULL, 0); 20 | luaL_register(l, "aroma", aroma_funcs); 21 | 22 | if (luaL_newmetatable(l, "aroma")) { 23 | // alias for aroma.new 24 | setfunction("__call", Canvas::_new); 25 | } 26 | 27 | lua_setmetatable(l, -2); 28 | return 1; 29 | } 30 | } 31 | 32 | 33 | // read an integer array from table on top of stack 34 | void readIntArray(lua_State *l, int *array, int count) { 35 | int buffsize = 10; // read 10 at a time 36 | 37 | int k = 0; 38 | while (count != 0) { 39 | int take = count < buffsize ? count : buffsize; 40 | for (int i = 0; i < take; i++) { 41 | lua_rawgeti(l, -(i+1), k+1); 42 | array[k++] = luaL_checkinteger(l, -1); 43 | } 44 | 45 | lua_pop(l, take); 46 | count -= take; 47 | } 48 | } 49 | 50 | void readArray(lua_State *l, double *array, int count) { 51 | int buffsize = 10; // read 10 at a time 52 | 53 | int k = 0; 54 | while (count != 0) { 55 | int take = count < buffsize ? count : buffsize; 56 | for (int i = 0; i < take; i++) { 57 | lua_rawgeti(l, -(i+1), k+1); 58 | array[k++] = luaL_checknumber(l, -1); 59 | } 60 | 61 | lua_pop(l, take); 62 | count -= take; 63 | } 64 | } 65 | 66 | 67 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Lua License 2 | ----------- 3 | 4 | Lua is licensed under the terms of the MIT license reproduced below. 5 | This means that Lua is free software and can be used for both academic 6 | and commercial purposes at absolutely no cost. 7 | 8 | For details and rationale, see http://www.lua.org/license.html . 9 | 10 | =============================================================================== 11 | 12 | Copyright (C) 1994-2012 Lua.org, PUC-Rio. 13 | 14 | Permission is hereby granted, free of charge, to any person obtaining a copy 15 | of this software and associated documentation files (the "Software"), to deal 16 | in the Software without restriction, including without limitation the rights 17 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | copies of the Software, and to permit persons to whom the Software is 19 | furnished to do so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be included in 22 | all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | THE SOFTWARE. 31 | 32 | =============================================================================== 33 | 34 | (end of COPYRIGHT) 35 | -------------------------------------------------------------------------------- /src/font.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "common.h" 6 | #include "image.h" 7 | 8 | using std::vector; 9 | 10 | namespace aroma { 11 | struct Letter { 12 | int letter; 13 | int width; 14 | }; 15 | 16 | struct Glyph { 17 | int letter; 18 | byte* bytes; 19 | int width; 20 | }; 21 | 22 | typedef vector LetterList; 23 | typedef vector GlyphList; 24 | 25 | class Font { 26 | protected: 27 | Image letter_tex; 28 | int line_height, max_width; 29 | int start_i; 30 | LetterList letters; 31 | vector letter_map; 32 | 33 | public: 34 | friend class Renderer; 35 | 36 | Font(Image letter_tex, int line_height, int max_w, LetterList letters); 37 | 38 | int push(lua_State* l) const; 39 | 40 | static int _new_image_font(lua_State *l); 41 | static int _gc(lua_State* l); 42 | static int _print(lua_State* l); 43 | 44 | // TODO 45 | // set/get line height and letter spacing 46 | // width of string calculation 47 | }; 48 | 49 | // collects all the glyphs in one place before building the texture for the 50 | // font 51 | class GlyphCache { 52 | private: 53 | int height; 54 | GlyphList glyphs; 55 | 56 | public: 57 | GlyphCache(); 58 | void add_glyph(int letter, byte* bytes, int w, int h); 59 | void add_glyph(int letter, ImageData data); 60 | 61 | Font build_font(); 62 | 63 | static int _new(lua_State* l); 64 | static int _add_glyph(lua_State* l); 65 | static int _to_font(lua_State* l); 66 | static int _gc(lua_State* l); 67 | }; 68 | 69 | class FontModule : public Bindable { 70 | public: 71 | const char* module_name(); 72 | void bind_all(lua_State* l); 73 | }; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | #define MEMERRMSG "not enough memory" 17 | 18 | 19 | #define luaM_reallocv(L,b,on,n,e) \ 20 | ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \ 21 | luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \ 22 | luaM_toobig(L)) 23 | 24 | #define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0) 25 | #define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0) 26 | #define luaM_freearray(L, b, n, t) luaM_reallocv(L, (b), n, 0, sizeof(t)) 27 | 28 | #define luaM_malloc(L,t) luaM_realloc_(L, NULL, 0, (t)) 29 | #define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t))) 30 | #define luaM_newvector(L,n,t) \ 31 | cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t))) 32 | 33 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 34 | if ((nelems)+1 > (size)) \ 35 | ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) 36 | 37 | #define luaM_reallocvector(L, v,oldn,n,t) \ 38 | ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t)))) 39 | 40 | 41 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 42 | size_t size); 43 | LUAI_FUNC void *luaM_toobig (lua_State *L); 44 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size, 45 | size_t size_elem, int limit, 46 | const char *errormsg); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /src/geometry.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | #include "common.h" 4 | #include "matrix.h" 5 | 6 | namespace aroma { 7 | 8 | struct Color { 9 | byte r, g, b, a; 10 | 11 | Color(); 12 | Color(byte r, byte g, byte b); 13 | Color(byte r, byte g, byte b, byte a); 14 | 15 | void print(); 16 | 17 | void bind(); // bind color to opengl current 18 | 19 | // return the floating point values 20 | float rf() const; 21 | float gf() const; 22 | float bf() const; 23 | float af() const; 24 | 25 | int push(lua_State* l); 26 | 27 | 28 | bool operator==(const Color &other) const; 29 | 30 | static Color pop(lua_State* l); 31 | 32 | static Color read(lua_State* l, int i); 33 | 34 | static byte MAX; 35 | 36 | static Color White; 37 | static Color Black; 38 | static Color Red; 39 | static Color Blue; 40 | static Color Green; 41 | static Color Gray; 42 | }; 43 | 44 | struct Point { 45 | double x, y, z, w; 46 | 47 | Point cross(Point other); 48 | Point dot(Point other); 49 | Point subtract(Point other); 50 | Point add(Point other); 51 | 52 | Point operator*(const Mat4 & mat) const; 53 | 54 | void print(); 55 | 56 | static Point from_array(double *values, int count); 57 | 58 | static int _new(lua_State *l); 59 | static int _print(lua_State *l); 60 | 61 | static Point pop(lua_State *l); 62 | static Point pop3(lua_State *l); 63 | 64 | static Point read2d(lua_State *l, int i); 65 | 66 | static void push(lua_State *l, double x, double y); 67 | static void push(lua_State *l, Point p); 68 | }; 69 | 70 | struct Rect { 71 | double x, y, w, h; 72 | 73 | static Rect from_point(Point p, double _w, double _h); 74 | static Rect pop(lua_State *l); 75 | static Rect read(lua_State*l, int i); 76 | }; 77 | 78 | } 79 | 80 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/lua-cjson-2.1.0-1.rockspec: -------------------------------------------------------------------------------- 1 | package = "lua-cjson" 2 | version = "2.1.0-1" 3 | 4 | source = { 5 | url = "http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.zip", 6 | } 7 | 8 | description = { 9 | summary = "A fast JSON encoding/parsing module", 10 | detailed = [[ 11 | The Lua CJSON module provides JSON support for Lua. It features: 12 | - Fast, standards compliant encoding/parsing routines 13 | - Full support for JSON with UTF-8, including decoding surrogate pairs 14 | - Optional run-time support for common exceptions to the JSON specification 15 | (infinity, NaN,..) 16 | - No dependencies on other libraries 17 | ]], 18 | homepage = "http://www.kyne.com.au/~mark/software/lua-cjson.php", 19 | license = "MIT" 20 | } 21 | 22 | dependencies = { 23 | "lua >= 5.1" 24 | } 25 | 26 | build = { 27 | type = "builtin", 28 | modules = { 29 | cjson = { 30 | sources = { "lua_cjson.c", "strbuf.c", "fpconv.c" }, 31 | defines = { 32 | -- LuaRocks does not support platform specific configuration for Solaris. 33 | -- Uncomment the line below on Solaris platforms if required. 34 | -- "USE_INTERNAL_ISINF" 35 | } 36 | } 37 | }, 38 | install = { 39 | lua = { 40 | ["cjson.util"] = "lua/cjson/util.lua" 41 | }, 42 | bin = { 43 | json2lua = "lua/json2lua.lua", 44 | lua2json = "lua/lua2json.lua" 45 | } 46 | }, 47 | -- Override default build options (per platform) 48 | platforms = { 49 | win32 = { modules = { cjson = { defines = { 50 | "DISABLE_INVALID_NUMBERS" 51 | } } } } 52 | }, 53 | copy_directories = { "tests" } 54 | } 55 | 56 | -- vi:ai et sw=4 ts=4: 57 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h,v 1.21.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define char2int(c) cast(int, cast(unsigned char, (c))) 21 | 22 | #define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z)) 23 | 24 | typedef struct Mbuffer { 25 | char *buffer; 26 | size_t n; 27 | size_t buffsize; 28 | } Mbuffer; 29 | 30 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 31 | 32 | #define luaZ_buffer(buff) ((buff)->buffer) 33 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 34 | #define luaZ_bufflen(buff) ((buff)->n) 35 | 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \ 41 | (buff)->buffsize = size) 42 | 43 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 44 | 45 | 46 | LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n); 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */ 50 | LUAI_FUNC int luaZ_lookahead (ZIO *z); 51 | 52 | 53 | 54 | /* --------- Private Part ------------------ */ 55 | 56 | struct Zio { 57 | size_t n; /* bytes still unread */ 58 | const char *p; /* current position in buffer */ 59 | lua_Reader reader; 60 | void* data; /* additional data */ 61 | lua_State *L; /* Lua state (for reader) */ 62 | }; 63 | 64 | 65 | LUAI_FUNC int luaZ_fill (ZIO *z); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | extern "C" { 7 | #include 8 | #include 9 | #include 10 | } 11 | 12 | #ifdef AROMA_NACL 13 | #include "nacl/gl.h" 14 | #else 15 | #define GL_GLEXT_PROTOTYPES 16 | #include 17 | #include 18 | #endif 19 | 20 | using namespace std; 21 | 22 | typedef unsigned char byte; 23 | 24 | typedef void(*AromaRegister)(lua_State *l); 25 | 26 | #define setint(name,val) lua_pushinteger(l, val);\ 27 | lua_setfield(l, -2, name) 28 | 29 | #define setnumber(name,val) lua_pushnumber(l, val);\ 30 | lua_setfield(l, -2, name) 31 | 32 | #define setbool(name,val) lua_pushboolean(l, val);\ 33 | lua_setfield(l, -2, name) 34 | 35 | #define setfunction(name,val) lua_pushcfunction(l, val);\ 36 | lua_setfield(l, -2, name) 37 | 38 | #define newuserdata(type) ((type*)lua_newuserdata(l, sizeof(type))) 39 | #define getself(type) ((type*)luaL_checkudata(l, 1, #type)) 40 | #define getselfi(type, i) ((type*)luaL_checkudata(l, i, #type)) 41 | 42 | #define set_new_func(name, func) lua_pushlightuserdata(l, this);\ 43 | lua_pushcclosure(l, func, 1);\ 44 | lua_setfield(l, -2, name) 45 | 46 | #define upvalue_self(type) ((type*)lua_touserdata(l, lua_upvalueindex(1))) 47 | 48 | #define $(val) #val ": " << val << " " 49 | 50 | // watch out this stuff breaks cmath 51 | #define __strx(x) #x 52 | #define __str(x) __strx(x) 53 | #define log(...) fprintf(stderr, " [" __FILE__ ":" __str(__LINE__) "] \033[1;33m>>\033[0m " __VA_ARGS__) 54 | #define err(...) fprintf(stderr, " [" __FILE__ ":" __str(__LINE__) "] \033[1;31m>>\033[0m " __VA_ARGS__) 55 | 56 | // void stackDump(lua_State *L); 57 | void readIntArray(lua_State *l, int *array, int count); 58 | void readArray(lua_State *l, double *array, int count); 59 | 60 | namespace aroma { 61 | extern const char *aroma_current_dir; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define ltm_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lobject.h" 16 | #include "lstate.h" 17 | #include "lstring.h" 18 | #include "ltable.h" 19 | #include "ltm.h" 20 | 21 | 22 | 23 | const char *const luaT_typenames[] = { 24 | "nil", "boolean", "userdata", "number", 25 | "string", "table", "function", "userdata", "thread", 26 | "proto", "upval" 27 | }; 28 | 29 | 30 | void luaT_init (lua_State *L) { 31 | static const char *const luaT_eventname[] = { /* ORDER TM */ 32 | "__index", "__newindex", 33 | "__gc", "__mode", "__eq", 34 | "__add", "__sub", "__mul", "__div", "__mod", 35 | "__pow", "__unm", "__len", "__lt", "__le", 36 | "__concat", "__call" 37 | }; 38 | int i; 39 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 41 | luaS_fix(G(L)->tmname[i]); /* never collect these names */ 42 | } 43 | } 44 | 45 | 46 | /* 47 | ** function to be used with macro "fasttm": optimized for absence of 48 | ** tag methods 49 | */ 50 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 51 | const TValue *tm = luaH_getstr(events, ename); 52 | lua_assert(event <= TM_EQ); 53 | if (ttisnil(tm)) { /* no tag method? */ 54 | events->flags |= cast_byte(1u<metatable; 66 | break; 67 | case LUA_TUSERDATA: 68 | mt = uvalue(o)->metatable; 69 | break; 70 | default: 71 | mt = G(L)->mt[ttype(o)]; 72 | } 73 | return (mt ? luaH_getstr(mt, G(L)->tmname[event]) : luaO_nilobject); 74 | } 75 | 76 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** a generic input stream interface 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lzio_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "llimits.h" 16 | #include "lmem.h" 17 | #include "lstate.h" 18 | #include "lzio.h" 19 | 20 | 21 | int luaZ_fill (ZIO *z) { 22 | size_t size; 23 | lua_State *L = z->L; 24 | const char *buff; 25 | lua_unlock(L); 26 | buff = z->reader(L, z->data, &size); 27 | lua_lock(L); 28 | if (buff == NULL || size == 0) return EOZ; 29 | z->n = size - 1; 30 | z->p = buff; 31 | return char2int(*(z->p++)); 32 | } 33 | 34 | 35 | int luaZ_lookahead (ZIO *z) { 36 | if (z->n == 0) { 37 | if (luaZ_fill(z) == EOZ) 38 | return EOZ; 39 | else { 40 | z->n++; /* luaZ_fill removed first byte; put back it */ 41 | z->p--; 42 | } 43 | } 44 | return char2int(*z->p); 45 | } 46 | 47 | 48 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 49 | z->L = L; 50 | z->reader = reader; 51 | z->data = data; 52 | z->n = 0; 53 | z->p = NULL; 54 | } 55 | 56 | 57 | /* --------------------------------------------------------------- read --- */ 58 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 59 | while (n) { 60 | size_t m; 61 | if (luaZ_lookahead(z) == EOZ) 62 | return n; /* return number of missing bytes */ 63 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 64 | memcpy(b, z->p, m); 65 | z->n -= m; 66 | z->p += m; 67 | b = (char *)b + m; 68 | n -= m; 69 | } 70 | return 0; 71 | } 72 | 73 | /* ------------------------------------------------------------------------ */ 74 | char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) { 75 | if (n > buff->buffsize) { 76 | if (n < LUA_MINBUFFER) n = LUA_MINBUFFER; 77 | luaZ_resizebuffer(L, buff, n); 78 | } 79 | return buff->buffer; 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /src/image.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "common.h" 5 | #include "geometry.h" 6 | #include "lua_binding.h" 7 | 8 | namespace aroma { 9 | int next_p2(int x); 10 | 11 | struct ImageData { 12 | GLenum format; 13 | GLenum type; 14 | 15 | int width, height; 16 | byte* bytes; 17 | 18 | ImageData(int width, int height, byte* bytes); // takes ownership of buffer 19 | ImageData(int width, int height); // creates the buffer 20 | ImageData(); 21 | 22 | void free(); // don't call if you've handed it off to lua 23 | void clear(const Color color); 24 | 25 | ImageData slice(int x, int y, int w, int h); 26 | 27 | void update(int x, int y, const ImageData & other); 28 | void apply_color_key(const Color key); 29 | 30 | #ifndef AROMA_NACL 31 | static bool from_memory_file(ImageData* d, const void* bytes, size_t len); 32 | static bool from_file(ImageData* d, const char* fname); 33 | #endif 34 | 35 | static int _gc(lua_State* l); 36 | static int _getWidth(lua_State* l); 37 | static int _getHeight(lua_State* l); 38 | 39 | static int _getPixel(lua_State* l); 40 | static int _setPixel(lua_State* l); 41 | 42 | static int _new(lua_State* l); 43 | 44 | int push(lua_State* l) const; 45 | }; 46 | 47 | struct Image { 48 | GLuint texid; 49 | int width, height; 50 | 51 | void bind() const; 52 | void update(int x, int y, const ImageData & data); 53 | 54 | void free(); 55 | 56 | static Image from_bytes(const byte* bytes, int width, int height, GLenum 57 | format = GL_RGBA, GLenum type = GL_UNSIGNED_BYTE); 58 | 59 | static Image from_data(const ImageData & data); 60 | 61 | static int _gc(lua_State* l); 62 | 63 | static int _getWidth(lua_State* l); 64 | static int _getHeight(lua_State* l); 65 | 66 | static int _setWrap(lua_State* l); 67 | static int _setFilter(lua_State* l); 68 | 69 | static int _new(lua_State* l); 70 | }; 71 | 72 | class ImageModule : public Bindable { 73 | const char* module_name(); 74 | void bind_all(lua_State* l); 75 | }; 76 | } 77 | 78 | -------------------------------------------------------------------------------- /src/canvas.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CANVAS_H_ 3 | #define CANVAS_H_ 4 | 5 | #include "common.h" 6 | #include "geometry.h" 7 | #include "context.h" 8 | 9 | namespace aroma { 10 | 11 | struct Viewport { 12 | void set(double t, double r, double b, double l); 13 | double top, left, bottom, right; 14 | bool is2d; 15 | double fov; // field of view for 3d mode 16 | 17 | Viewport(double width, double height); 18 | void reshape(); // reshape opengl to this viewport 19 | double getWidth(); 20 | double getHeight(); 21 | 22 | void print(); 23 | }; 24 | 25 | class Canvas { 26 | public: 27 | Canvas(GLContext* context); 28 | void push(lua_State *l); // push this canvas to top of stack 29 | void reshape(); // shape the projection matrix 30 | 31 | int width(); 32 | int height(); 33 | 34 | GLContext* context; 35 | Viewport view; 36 | 37 | // double width, height; 38 | Color paint; 39 | Color clearColor; 40 | 41 | static int _new(lua_State *l); // create new canvas 42 | 43 | static int _call(lua_State *l); // call the canvas object 44 | 45 | // instance methods 46 | 47 | static int _run(lua_State *l); // run the game loop 48 | 49 | static int _clearColor(lua_State *l); 50 | static int _clear(lua_State *l); 51 | 52 | static int _viewport(lua_State *l); // set 2d viewport 53 | static int _view3d(lua_State *l); 54 | 55 | static int _look(lua_State *l); 56 | static int _strip(lua_State *l); 57 | 58 | static int _save(lua_State *l); 59 | static int _restore(lua_State *l); 60 | 61 | static int _rotate(lua_State *l); 62 | static int _scale(lua_State *l); 63 | static int _translate(lua_State *l); 64 | 65 | static int _noise(lua_State *l); 66 | 67 | static int _getTime(lua_State *l); 68 | 69 | static int _key(lua_State *l); 70 | 71 | static int _key_down(lua_State *l); 72 | static int _key_up(lua_State *l); 73 | 74 | static int _rect(lua_State *l); 75 | static int _line(lua_State *l); 76 | static int _flush(lua_State *l); 77 | 78 | static int _setMouse(lua_State *l); 79 | 80 | static int _hideMouse(lua_State *l); 81 | static int _showMouse(lua_State *l); 82 | }; 83 | 84 | } 85 | 86 | #endif /* CANVAS_H_ */ 87 | 88 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | #define luaD_checkstack(L,n) \ 17 | if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ 18 | luaD_growstack(L, n); \ 19 | else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); 20 | 21 | 22 | #define incr_top(L) {luaD_checkstack(L,1); L->top++;} 23 | 24 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 25 | #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 26 | 27 | #define saveci(L,p) ((char *)(p) - (char *)L->base_ci) 28 | #define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) 29 | 30 | 31 | /* results from luaD_precall */ 32 | #define PCRLUA 0 /* initiated a call to a Lua function */ 33 | #define PCRC 1 /* did a call to a C function */ 34 | #define PCRYIELD 2 /* C funtion yielded */ 35 | 36 | 37 | /* type of protected functions, to be ran by `runprotected' */ 38 | typedef void (*Pfunc) (lua_State *L, void *ud); 39 | 40 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); 41 | LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); 42 | LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 45 | ptrdiff_t oldtop, ptrdiff_t ef); 46 | LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); 47 | LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); 48 | LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 49 | LUAI_FUNC void luaD_growstack (lua_State *L, int n); 50 | 51 | LUAI_FUNC void luaD_throw (lua_State *L, int errcode); 52 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 53 | 54 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /src/context.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "context.h" 3 | #include "common.h" 4 | 5 | namespace aroma { 6 | #ifndef AROMA_NACL 7 | 8 | GLFWContext::GLFWContext(int w, int h, const char* title) 9 | : w(w), h(h), title(title), created(false) { } 10 | 11 | bool GLFWContext::make_window() { 12 | glfwInit(); 13 | 14 | #ifdef __APPLE__ 15 | chdir(aroma_current_dir); 16 | #endif 17 | glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); 18 | bool ok = glfwOpenWindow( 19 | w, h, 20 | 8, 8, 8, 21 | 8, // alpha buffer 22 | 24, // depth buffer 23 | 0, // stencil buffer 24 | GLFW_WINDOW 25 | ); 26 | 27 | if (!ok) { 28 | glfwTerminate(); 29 | return false; 30 | } 31 | 32 | glfwSetWindowTitle(title); 33 | glfwEnable(GLFW_STICKY_KEYS); 34 | 35 | // glfwSetWindowSizeCallback(resize); 36 | 37 | /* */ 38 | glEnable(GL_TEXTURE_2D); 39 | glEnable(GL_BLEND); 40 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 41 | /* */ 42 | 43 | glShadeModel(GL_FLAT); 44 | // glEnable(GL_LIGHTING); 45 | // glEnable(GL_LIGHT0); 46 | 47 | GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; 48 | GLfloat diffuse[] = {0.9, 0.9, 0.9, 1.0}; 49 | GLfloat specular[] = {0.5, 0.5, 0.5, 1.0}; 50 | 51 | glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); 52 | glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); 53 | glLightfv(GL_LIGHT0, GL_SPECULAR, specular); 54 | 55 | 56 | // glEnable(GL_COLOR_MATERIAL); 57 | // glColorMaterial(GL_FRONT, GL_DIFFUSE); 58 | created = true; 59 | return true; 60 | } 61 | 62 | bool GLFWContext::make_current() { 63 | if (!created && !make_window()) return false; 64 | return true; 65 | } 66 | 67 | void GLFWContext::resize(const int w, const int h) { 68 | log("glfw window can't resize!"); 69 | } 70 | 71 | void GLFWContext::flush() { 72 | glfwSwapBuffers(); 73 | glfwSleep(0.005); 74 | } 75 | 76 | int GLFWContext::width() { 77 | return w; 78 | } 79 | 80 | int GLFWContext::height() { 81 | return h; 82 | } 83 | 84 | double GLFWContext::get_time() { 85 | return glfwGetTime(); 86 | } 87 | 88 | bool GLFWContext::is_flushing() { 89 | return true; // not used 90 | } 91 | 92 | #endif 93 | 94 | } 95 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/dtoa_config.h: -------------------------------------------------------------------------------- 1 | #ifndef _DTOA_CONFIG_H 2 | #define _DTOA_CONFIG_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /* Ensure dtoa.c does not USE_LOCALE. Lua CJSON must not use locale 9 | * aware conversion routines. */ 10 | #undef USE_LOCALE 11 | 12 | /* dtoa.c should not touch errno, Lua CJSON does not use it, and it 13 | * may not be threadsafe */ 14 | #define NO_ERRNO 15 | 16 | #define Long int32_t 17 | #define ULong uint32_t 18 | #define Llong int64_t 19 | #define ULLong uint64_t 20 | 21 | #ifdef IEEE_BIG_ENDIAN 22 | #define IEEE_MC68k 23 | #else 24 | #define IEEE_8087 25 | #endif 26 | 27 | #define MALLOC(n) xmalloc(n) 28 | 29 | static void *xmalloc(size_t size) 30 | { 31 | void *p; 32 | 33 | p = malloc(size); 34 | if (!p) { 35 | fprintf(stderr, "Out of memory"); 36 | abort(); 37 | } 38 | 39 | return p; 40 | } 41 | 42 | #ifdef MULTIPLE_THREADS 43 | 44 | /* Enable locking to support multi-threaded applications */ 45 | 46 | #include 47 | 48 | static pthread_mutex_t private_dtoa_lock[2] = { 49 | PTHREAD_MUTEX_INITIALIZER, 50 | PTHREAD_MUTEX_INITIALIZER 51 | }; 52 | 53 | #define ACQUIRE_DTOA_LOCK(n) do { \ 54 | int r = pthread_mutex_lock(&private_dtoa_lock[n]); \ 55 | if (r) { \ 56 | fprintf(stderr, "pthread_mutex_lock failed with %d\n", r); \ 57 | abort(); \ 58 | } \ 59 | } while (0) 60 | 61 | #define FREE_DTOA_LOCK(n) do { \ 62 | int r = pthread_mutex_unlock(&private_dtoa_lock[n]); \ 63 | if (r) { \ 64 | fprintf(stderr, "pthread_mutex_unlock failed with %d\n", r);\ 65 | abort(); \ 66 | } \ 67 | } while (0) 68 | 69 | #endif /* MULTIPLE_THREADS */ 70 | 71 | #endif /* _DTOA_CONFIG_H */ 72 | 73 | /* vi:ai et sw=4 ts=4: 74 | */ 75 | -------------------------------------------------------------------------------- /examples/tetris/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NaCl Tetris 6 | 7 | 47 | 58 | 59 | 60 |

NaCl Tetris

61 |
62 | 73 | 74 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /site/index.html: -------------------------------------------------------------------------------- 1 | 2 | Fork me on GitHub 3 | 4 | 5 |
6 |
7 | $render{"leader.md"} 8 |
9 | 10 | 26 | 27 |
28 |

Demo Games

29 |
30 | 31 |
32 |
{
33 |
34 |
35 | Play 38 |
39 | 40 |
41 | Source 43 |
44 | 45 |
Volcanox
46 |
47 | 48 |
49 |
50 | Play 53 |
54 |
55 | Source 58 |
59 |
NaCl Tetris
60 |
61 |
}
62 |
63 | 64 |
65 | $render{"index.md"} 66 |
67 |
68 | 69 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PLATFORM="`uname -s`" 4 | [ "$1" ] && VERSION="$1" || VERSION="2.1.0" 5 | 6 | set -e 7 | 8 | # Portable "ggrep -A" replacement. 9 | # Work around Solaris awk record limit of 2559 bytes. 10 | # contextgrep PATTERN POST_MATCH_LINES 11 | contextgrep() { 12 | cut -c -2500 | awk "/$1/ { count = ($2 + 1) } count > 0 { count--; print }" 13 | } 14 | 15 | do_tests() { 16 | echo 17 | cd tests 18 | lua -e 'print("Testing Lua CJSON version " .. require("cjson")._VERSION)' 19 | ./test.lua | contextgrep 'FAIL|Summary' 3 | grep -v PASS | cut -c -150 20 | cd .. 21 | } 22 | 23 | echo "===== Setting LuaRocks PATH =====" 24 | eval "`luarocks path`" 25 | 26 | echo "===== Building UTF-8 test data =====" 27 | ( cd tests && ./genutf8.pl; ) 28 | 29 | echo "===== Cleaning old build data =====" 30 | make clean 31 | rm -f tests/cjson.so 32 | 33 | echo "===== Verifying cjson.so is not installed =====" 34 | 35 | cd tests 36 | if lua -e 'require "cjson"' 2>/dev/null 37 | then 38 | cat < "$LOG" 82 | RPM="`awk '/^Wrote: / && ! /debuginfo/ { print $2}' < "$LOG"`" 83 | sudo -- rpm -Uvh \"$RPM\" 84 | do_tests 85 | sudo -- rpm -e lua-cjson 86 | rm -f "$LOG" 87 | else 88 | echo "==> skipping, $TGZ not found" 89 | fi 90 | fi 91 | 92 | # vi:ai et sw=4 ts=4: 93 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/lua-cjson.spec: -------------------------------------------------------------------------------- 1 | %define luaver 5.1 2 | %define lualibdir %{_libdir}/lua/%{luaver} 3 | %define luadatadir %{_datadir}/lua/%{luaver} 4 | 5 | Name: lua-cjson 6 | Version: 2.1.0 7 | Release: 1%{?dist} 8 | Summary: A fast JSON encoding/parsing module for Lua 9 | 10 | Group: Development/Libraries 11 | License: MIT 12 | URL: http://www.kyne.com.au/~mark/software/lua-cjson/ 13 | Source0: http://www.kyne.com.au/~mark/software/lua-cjson/download/lua-cjson-%{version}.tar.gz 14 | BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) 15 | 16 | BuildRequires: lua >= %{luaver}, lua-devel >= %{luaver} 17 | Requires: lua >= %{luaver} 18 | 19 | %description 20 | The Lua CJSON module provides JSON support for Lua. It features: 21 | - Fast, standards compliant encoding/parsing routines 22 | - Full support for JSON with UTF-8, including decoding surrogate pairs 23 | - Optional run-time support for common exceptions to the JSON specification 24 | (infinity, NaN,..) 25 | - No dependencies on other libraries 26 | 27 | 28 | %prep 29 | %setup -q 30 | 31 | 32 | %build 33 | make %{?_smp_mflags} CFLAGS="%{optflags}" LUA_INCLUDE_DIR="%{_includedir}" 34 | 35 | 36 | %install 37 | rm -rf "$RPM_BUILD_ROOT" 38 | make install DESTDIR="$RPM_BUILD_ROOT" LUA_CMODULE_DIR="%{lualibdir}" 39 | make install-extra DESTDIR="$RPM_BUILD_ROOT" LUA_MODULE_DIR="%{luadatadir}" \ 40 | LUA_BIN_DIR="%{_bindir}" 41 | 42 | 43 | %clean 44 | rm -rf "$RPM_BUILD_ROOT" 45 | 46 | 47 | %preun 48 | /bin/rm -f "%{luadatadir}/cjson/tests/utf8.dat" 49 | 50 | 51 | %files 52 | %defattr(-,root,root,-) 53 | %doc LICENSE NEWS performance.html performance.txt manual.html manual.txt rfc4627.txt THANKS 54 | %{lualibdir}/* 55 | %{luadatadir}/* 56 | %{_bindir}/* 57 | 58 | 59 | %changelog 60 | * Thu Mar 1 2012 Mark Pulford - 2.1.0-1 61 | - Update for 2.1.0 62 | 63 | * Sun Jan 22 2012 Mark Pulford - 2.0.0-1 64 | - Update for 2.0.0 65 | - Install lua2json / json2lua utilities 66 | 67 | * Wed Nov 27 2011 Mark Pulford - 1.0.4-1 68 | - Update for 1.0.4 69 | 70 | * Wed Sep 15 2011 Mark Pulford - 1.0.3-1 71 | - Update for 1.0.3 72 | 73 | * Sun May 29 2011 Mark Pulford - 1.0.2-1 74 | - Update for 1.0.2 75 | 76 | * Sun May 10 2011 Mark Pulford - 1.0.1-1 77 | - Update for 1.0.1 78 | 79 | * Sun May 1 2011 Mark Pulford - 1.0-1 80 | - Initial package 81 | -------------------------------------------------------------------------------- /site/index.md: -------------------------------------------------------------------------------- 1 | 2 | ## How It Works 3 | 4 | Native Client files are distributed as `.nexe` binaries where are compiled for 5 | both 64-bit and 32-bit computers. Aroma comes as a compiled `.nexe` file that's 6 | ready to use after uploading to your server. All you need to do is upload your 7 | game alongside Aroma. 8 | 9 | ### Reusing Your Browser 10 | 11 | In order to keep the `.nexe` binary small, Aroma reuses your browser to 12 | accomplish many tasks without depending on additional libraries. Things like 13 | rendering fonts and decoding images are handled by the `canvas` tag. The 14 | loading of game resources is transparently turned into HTTP requests to your 15 | sever. 16 | 17 | ### Asynchronous Loading 18 | 19 | Aroma loads all of your game code from the web. You typically will upload your 20 | code alongside Aroma's `.nexe` and `.js` files. This enables you to quickly 21 | deploy changes without having to recompile anything. 22 | 23 | If you've ever done web programming you're probably familiar with making 24 | asynchronous requests to a server to fetch resources by providing some sort of 25 | a callback function. On the other hand, when loading code in Lua you typically 26 | write something synchronous like: 27 | 28 | ```lua 29 | require "mygame.enemy" 30 | ``` 31 | 32 | Aroma translates this call into an asynchronous request to the browser, 33 | blocking the execution of the game until the resource has been fetched. 34 | Combined with the caching provided by the browser, this makes loading code from 35 | the web pleasant. 36 | 37 | Aroma also has the ability to batch asynchronous requests together in order to 38 | perform them faster. 39 | 40 | ### LÖVE API 41 | 42 | Aroma implements parts of the [LÖVE][3] Lua API, so if you've got a game 43 | already written it's easy to port. 44 | 45 | [1]: https://developers.google.com/native-client/ 46 | [2]: https://lua.org 47 | [3]: https://love2d.org 48 | 49 | 50 | ## Get Started Today 51 | 52 | Aroma is early in development but ready for testing. Get started with the 53 | following resources: 54 | 55 | * Download the latest version: aroma-$version.zip 56 | * Read the beginning tutorial 57 | * JavaScript Reference 58 | * Lua Reference 59 | * Changelog 60 | 61 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include "lobject.h" 11 | #include "lzio.h" 12 | 13 | 14 | #define FIRST_RESERVED 257 15 | 16 | /* maximum length of a reserved word */ 17 | #define TOKEN_LEN (sizeof("function")/sizeof(char)) 18 | 19 | 20 | /* 21 | * WARNING: if you change the order of this enumeration, 22 | * grep "ORDER RESERVED" 23 | */ 24 | enum RESERVED { 25 | /* terminal symbols denoted by reserved words */ 26 | TK_AND = FIRST_RESERVED, TK_BREAK, 27 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 28 | TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 29 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 30 | /* other terminal symbols */ 31 | TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER, 32 | TK_NAME, TK_STRING, TK_EOS 33 | }; 34 | 35 | /* number of reserved words */ 36 | #define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1)) 37 | 38 | 39 | /* array with token `names' */ 40 | LUAI_DATA const char *const luaX_tokens []; 41 | 42 | 43 | typedef union { 44 | lua_Number r; 45 | TString *ts; 46 | } SemInfo; /* semantics information */ 47 | 48 | 49 | typedef struct Token { 50 | int token; 51 | SemInfo seminfo; 52 | } Token; 53 | 54 | 55 | typedef struct LexState { 56 | int current; /* current character (charint) */ 57 | int linenumber; /* input line counter */ 58 | int lastline; /* line of last token `consumed' */ 59 | Token t; /* current token */ 60 | Token lookahead; /* look ahead token */ 61 | struct FuncState *fs; /* `FuncState' is private to the parser */ 62 | struct lua_State *L; 63 | ZIO *z; /* input stream */ 64 | Mbuffer *buff; /* buffer for tokens */ 65 | TString *source; /* current source name */ 66 | char decpoint; /* locale decimal point */ 67 | } LexState; 68 | 69 | 70 | LUAI_FUNC void luaX_init (lua_State *L); 71 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 72 | TString *source); 73 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 74 | LUAI_FUNC void luaX_next (LexState *ls); 75 | LUAI_FUNC void luaX_lookahead (LexState *ls); 76 | LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); 77 | LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); 78 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 79 | 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c,v 1.70.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lmem_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "ldebug.h" 16 | #include "ldo.h" 17 | #include "lmem.h" 18 | #include "lobject.h" 19 | #include "lstate.h" 20 | 21 | 22 | 23 | /* 24 | ** About the realloc function: 25 | ** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 26 | ** (`osize' is the old size, `nsize' is the new size) 27 | ** 28 | ** Lua ensures that (ptr == NULL) iff (osize == 0). 29 | ** 30 | ** * frealloc(ud, NULL, 0, x) creates a new block of size `x' 31 | ** 32 | ** * frealloc(ud, p, x, 0) frees the block `p' 33 | ** (in this specific case, frealloc must return NULL). 34 | ** particularly, frealloc(ud, NULL, 0, 0) does nothing 35 | ** (which is equivalent to free(NULL) in ANSI C) 36 | ** 37 | ** frealloc returns NULL if it cannot create or reallocate the area 38 | ** (any reallocation to an equal or smaller size cannot fail!) 39 | */ 40 | 41 | 42 | 43 | #define MINSIZEARRAY 4 44 | 45 | 46 | void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, 47 | int limit, const char *errormsg) { 48 | void *newblock; 49 | int newsize; 50 | if (*size >= limit/2) { /* cannot double it? */ 51 | if (*size >= limit) /* cannot grow even a little? */ 52 | luaG_runerror(L, errormsg); 53 | newsize = limit; /* still have at least one free place */ 54 | } 55 | else { 56 | newsize = (*size)*2; 57 | if (newsize < MINSIZEARRAY) 58 | newsize = MINSIZEARRAY; /* minimum size */ 59 | } 60 | newblock = luaM_reallocv(L, block, *size, newsize, size_elems); 61 | *size = newsize; /* update only when everything else is OK */ 62 | return newblock; 63 | } 64 | 65 | 66 | void *luaM_toobig (lua_State *L) { 67 | luaG_runerror(L, "memory allocation error: block too big"); 68 | return NULL; /* to avoid warnings */ 69 | } 70 | 71 | 72 | 73 | /* 74 | ** generic allocation routine. 75 | */ 76 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 77 | global_State *g = G(L); 78 | lua_assert((osize == 0) == (block == NULL)); 79 | block = (*g->frealloc)(g->ud, block, osize, nsize); 80 | if (block == NULL && nsize > 0) 81 | luaD_throw(L, LUA_ERRMEM); 82 | lua_assert((nsize == 0) == (block == NULL)); 83 | g->totalbytes = (g->totalbytes - osize) + nsize; 84 | return block; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression descriptor 17 | */ 18 | 19 | typedef enum { 20 | VVOID, /* no value */ 21 | VNIL, 22 | VTRUE, 23 | VFALSE, 24 | VK, /* info = index of constant in `k' */ 25 | VKNUM, /* nval = numerical value */ 26 | VLOCAL, /* info = local register */ 27 | VUPVAL, /* info = index of upvalue in `upvalues' */ 28 | VGLOBAL, /* info = index of table; aux = index of global name in `k' */ 29 | VINDEXED, /* info = table register; aux = index register (or `k') */ 30 | VJMP, /* info = instruction pc */ 31 | VRELOCABLE, /* info = instruction pc */ 32 | VNONRELOC, /* info = result register */ 33 | VCALL, /* info = instruction pc */ 34 | VVARARG /* info = instruction pc */ 35 | } expkind; 36 | 37 | typedef struct expdesc { 38 | expkind k; 39 | union { 40 | struct { int info, aux; } s; 41 | lua_Number nval; 42 | } u; 43 | int t; /* patch list of `exit when true' */ 44 | int f; /* patch list of `exit when false' */ 45 | } expdesc; 46 | 47 | 48 | typedef struct upvaldesc { 49 | lu_byte k; 50 | lu_byte info; 51 | } upvaldesc; 52 | 53 | 54 | struct BlockCnt; /* defined in lparser.c */ 55 | 56 | 57 | /* state needed to generate code for a given function */ 58 | typedef struct FuncState { 59 | Proto *f; /* current function header */ 60 | Table *h; /* table to find (and reuse) elements in `k' */ 61 | struct FuncState *prev; /* enclosing function */ 62 | struct LexState *ls; /* lexical state */ 63 | struct lua_State *L; /* copy of the Lua state */ 64 | struct BlockCnt *bl; /* chain of current blocks */ 65 | int pc; /* next position to code (equivalent to `ncode') */ 66 | int lasttarget; /* `pc' of last `jump target' */ 67 | int jpc; /* list of pending jumps to `pc' */ 68 | int freereg; /* first free register */ 69 | int nk; /* number of elements in `k' */ 70 | int np; /* number of elements in `p' */ 71 | short nlocvars; /* number of elements in `locvars' */ 72 | lu_byte nactvar; /* number of active local variables */ 73 | upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */ 74 | unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */ 75 | } FuncState; 76 | 77 | 78 | LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 79 | const char *name); 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /site/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | $if{"title"}[[$title - ]]Aroma 6 | 7 | 8 | 9 | $analytics{"UA-136625-1"} 10 | 11 | 12 |
13 |
14 | 29 | 30 |
31 |

aroma

32 |
33 |
34 |
35 | The Native Client game engine powered by Lua 36 |
37 |
38 |
39 | 40 | 47 | 48 |
49 | $body 50 |
51 |
52 | 56 | 57 | 58 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/nacl/gl_context.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "nacl/aroma.h" 3 | #include "nacl/gl_context.h" 4 | #include "renderer.h" 5 | #include "common.h" 6 | 7 | namespace aroma { 8 | 9 | void default_flush_callback(void *data, int32_t result) { 10 | OpenGLContext* context = (OpenGLContext*)data; 11 | context->render(); 12 | } 13 | 14 | OpenGLContext::OpenGLContext(pp::Instance* instance) : 15 | flushing(false), 16 | pp::Graphics3DClient(instance), 17 | instance(instance) 18 | { 19 | pp::Module *module = pp::Module::Get(); 20 | assert(module); 21 | gles2_interface = static_cast( 22 | module->GetBrowserInterface(PPB_OPENGLES2_INTERFACE)); 23 | assert(gles2_interface); 24 | } 25 | 26 | OpenGLContext::~OpenGLContext() { 27 | glSetCurrentContextPPAPI(0); 28 | } 29 | 30 | bool OpenGLContext::make_current() { 31 | bool is_init = graphics.is_null(); 32 | if (graphics.is_null()) { 33 | log("init graphics\n"); 34 | int32_t attribs[] = { 35 | PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, 36 | PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, 37 | PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, 38 | PP_GRAPHICS3DATTRIB_SAMPLES, 0, 39 | PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0, 40 | PP_GRAPHICS3DATTRIB_WIDTH, size.width(), 41 | PP_GRAPHICS3DATTRIB_HEIGHT, size.height(), 42 | PP_GRAPHICS3DATTRIB_NONE 43 | }; 44 | graphics = pp::Graphics3D(instance, pp::Graphics3D(), attribs); 45 | if (graphics.is_null()) { 46 | glSetCurrentContextPPAPI(0); 47 | return false; 48 | } 49 | instance->BindGraphics(graphics); 50 | } 51 | 52 | glSetCurrentContextPPAPI(graphics.pp_resource()); 53 | 54 | if (is_init && !renderer->init()) { 55 | return false; 56 | } 57 | 58 | return true; 59 | } 60 | 61 | void OpenGLContext::resize(const int width, const int height) { 62 | log("resize buffers\n"); 63 | size = pp::Size(width, height); 64 | if (!graphics.is_null()) { 65 | graphics.ResizeBuffers(width, height); 66 | } 67 | } 68 | 69 | void OpenGLContext::flush() { 70 | flushing = true; 71 | graphics.SwapBuffers(pp::CompletionCallback(&default_flush_callback, this)); 72 | } 73 | 74 | void OpenGLContext::Graphics3DContextLost() { 75 | assert(!"++ Lost graphics context"); 76 | } 77 | 78 | void OpenGLContext::render() { 79 | flushing = false; 80 | renderer->tick(); 81 | } 82 | 83 | int OpenGLContext::width() { 84 | return size.width(); 85 | } 86 | 87 | int OpenGLContext::height() { 88 | return size.height(); 89 | } 90 | 91 | double OpenGLContext::get_time() { 92 | return pp::Module::Get()->core()->GetTimeTicks(); 93 | } 94 | 95 | void OpenGLContext::set_renderer(Renderer *r) { 96 | renderer = r; 97 | } 98 | 99 | bool OpenGLContext::is_flushing() { 100 | return flushing; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aroma v0.0.3 2 | #### a game engine 3 | Leaf Corcoran, 2012 4 | 5 | 6 | [Changelog](http://leafo.net/aroma/changelog.html) 7 | 8 | ## About 9 | 10 | Aroma is game creation framework/platform that targets [Chrome's Native 11 | Client][1]. It lets you create games that can be distributed through the Chrome 12 | Web Store. 13 | 14 | Aroma games are written in the Lua programming language. 15 | 16 | Aroma implements the [LÖVE][2] API in order to make porting existing games 17 | easy. 18 | 19 | ## How it works 20 | 21 | Upload Aroma's `.nexe` binaries, `.nmf` file, and javascript support to a 22 | directory. Then upload your entire game (Lua code, images, and audio) alongside 23 | it and write a simple html file. 24 | 25 | See the [tutorial][3] for a more detailed guide. 26 | 27 | Aroma facilitates resource loading for you. It also handles drawing to an 28 | OpenGL powered canvas. Aroma will reuse features of the browser whenever 29 | possible, for things like decoding images, playing audio and downloading code. 30 | 31 | ## Dependencies 32 | 33 | * [Lua 5.1](http://lua.org) 34 | * [Lua CJSON](http://www.kyne.com.au/~mark/software/lua-cjson.php) 35 | 36 | ## How To Build 37 | 38 | Building can be a bit challenging, but here is a brief overview. I build Aroma 39 | on Linux. It should work on OSX. If you're on Windows you're on your own! (But 40 | if you figure it out, tell me and I'll update this guide) 41 | 42 | The following dependencies are required before building: 43 | 44 | * [tup](http://gittup.org/tup/index.html) -- the build system 45 | * [git](http://git-scm.com) -- used in the 32 bit build script 46 | * [NaCL SDK](https://developers.google.com/native-client/sdk/download) -- Pepper 18 47 | * [moonscript-dev-1](http://moonscript.org/#source) 48 | * [CoffeeScript](http://coffeescript.org) 49 | * [xxd](http://linux.die.net/man/1/xxd) 50 | 51 | *If you want to build the website (which you probably don't), you need 52 | [sitegen](http://leafo.net/sitegen) and [lessphp](http://leafo.net/lessphp)* 53 | 54 | After all the dependencies are set up, head into the `nacl` folder and run: 55 | 56 | $ ./installs_deps 57 | 58 | This will download and extract Lua 5.1.2 and Lua CJSON. 59 | 60 | Next, head to the root directory, set up tup and tell it to build! 61 | 62 | $ tup init 63 | $ tup upd 64 | 65 | By default this will build the 64 bit version of Aroma. I've provided a 66 | makefile in the `nacl` folder with a directive for building 32 bit, just run: 67 | 68 | $ make 32 69 | 70 | If you want to make tup build 32 by default then edit `tup.config` in the root 71 | directory, and uncomment the line: 72 | 73 | CONFIG_NACL_ARCH=i686 74 | 75 | And finally, I use tup for this reason, run this command: 76 | 77 | $ tup monitor -a -f 78 | 79 | This watches the filesystem and builds what's needed when you change something. 80 | 81 | [1]: https://developers.google.com/native-client/ 82 | [2]: http://love2d.org 83 | [3]: http://leafo.net/aroma/tutorial.html 84 | 85 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/llimits.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Limits, basic types, and some other `installation-dependent' definitions 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llimits_h 8 | #define llimits_h 9 | 10 | 11 | #include 12 | #include 13 | 14 | 15 | #include "lua.h" 16 | 17 | 18 | typedef LUAI_UINT32 lu_int32; 19 | 20 | typedef LUAI_UMEM lu_mem; 21 | 22 | typedef LUAI_MEM l_mem; 23 | 24 | 25 | 26 | /* chars used as small naturals (so that `char' is reserved for characters) */ 27 | typedef unsigned char lu_byte; 28 | 29 | 30 | #define MAX_SIZET ((size_t)(~(size_t)0)-2) 31 | 32 | #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) 33 | 34 | 35 | #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ 36 | 37 | /* 38 | ** conversion of pointer to integer 39 | ** this is for hashing only; there is no problem if the integer 40 | ** cannot hold the whole pointer value 41 | */ 42 | #define IntPoint(p) ((unsigned int)(lu_mem)(p)) 43 | 44 | 45 | 46 | /* type to ensure maximum alignment */ 47 | typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; 48 | 49 | 50 | /* result of a `usual argument conversion' over lua_Number */ 51 | typedef LUAI_UACNUMBER l_uacNumber; 52 | 53 | 54 | /* internal assertions for in-house debugging */ 55 | #ifdef lua_assert 56 | 57 | #define check_exp(c,e) (lua_assert(c), (e)) 58 | #define api_check(l,e) lua_assert(e) 59 | 60 | #else 61 | 62 | #define lua_assert(c) ((void)0) 63 | #define check_exp(c,e) (e) 64 | #define api_check luai_apicheck 65 | 66 | #endif 67 | 68 | 69 | #ifndef UNUSED 70 | #define UNUSED(x) ((void)(x)) /* to avoid warnings */ 71 | #endif 72 | 73 | 74 | #ifndef cast 75 | #define cast(t, exp) ((t)(exp)) 76 | #endif 77 | 78 | #define cast_byte(i) cast(lu_byte, (i)) 79 | #define cast_num(i) cast(lua_Number, (i)) 80 | #define cast_int(i) cast(int, (i)) 81 | 82 | 83 | 84 | /* 85 | ** type for virtual-machine instructions 86 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) 87 | */ 88 | typedef lu_int32 Instruction; 89 | 90 | 91 | 92 | /* maximum stack for a Lua function */ 93 | #define MAXSTACK 250 94 | 95 | 96 | 97 | /* minimum size for the string table (must be power of 2) */ 98 | #ifndef MINSTRTABSIZE 99 | #define MINSTRTABSIZE 32 100 | #endif 101 | 102 | 103 | /* minimum size for string buffer */ 104 | #ifndef LUA_MINBUFFER 105 | #define LUA_MINBUFFER 32 106 | #endif 107 | 108 | 109 | #ifndef lua_lock 110 | #define lua_lock(L) ((void) 0) 111 | #define lua_unlock(L) ((void) 0) 112 | #endif 113 | 114 | #ifndef luai_threadyield 115 | #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} 116 | #endif 117 | 118 | 119 | /* 120 | ** macro to control inclusion of some hard tests on stack reallocation 121 | */ 122 | #ifndef HARDSTACKTESTS 123 | #define condhardstacktests(x) ((void)0) 124 | #else 125 | #define condhardstacktests(x) x 126 | #endif 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h,v 1.48.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums 25 | */ 26 | typedef enum BinOpr { 27 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW, 28 | OPR_CONCAT, 29 | OPR_NE, OPR_EQ, 30 | OPR_LT, OPR_LE, OPR_GT, OPR_GE, 31 | OPR_AND, OPR_OR, 32 | OPR_NOBINOPR 33 | } BinOpr; 34 | 35 | 36 | typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 37 | 38 | 39 | #define getcode(fs,e) ((fs)->f->code[(e)->u.s.info]) 40 | 41 | #define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx) 42 | 43 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 44 | 45 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 46 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); 47 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 48 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 49 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 50 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 51 | LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); 52 | LUAI_FUNC int luaK_numberK (FuncState *fs, lua_Number r); 53 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 54 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 55 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 56 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 57 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 58 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 59 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 60 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 61 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 62 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 63 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 64 | LUAI_FUNC int luaK_jump (FuncState *fs); 65 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 66 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 67 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 68 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 69 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 70 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v); 71 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 72 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2); 73 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 74 | 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/g_fmt.c: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * 3 | * The author of this software is David M. Gay. 4 | * 5 | * Copyright (c) 1991, 1996 by Lucent Technologies. 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose without fee is hereby granted, provided that this entire notice 9 | * is included in all copies of any software which is or includes a copy 10 | * or modification of this software and in all copies of the supporting 11 | * documentation for such software. 12 | * 13 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY 15 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 16 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 | * 18 | ***************************************************************/ 19 | 20 | /* g_fmt(buf,x) stores the closest decimal approximation to x in buf; 21 | * it suffices to declare buf 22 | * char buf[32]; 23 | */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | extern char *dtoa(double, int, int, int *, int *, char **); 29 | extern int g_fmt(char *, double, int); 30 | extern void freedtoa(char*); 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | int 36 | fpconv_g_fmt(char *b, double x, int precision) 37 | { 38 | register int i, k; 39 | register char *s; 40 | int decpt, j, sign; 41 | char *b0, *s0, *se; 42 | 43 | b0 = b; 44 | #ifdef IGNORE_ZERO_SIGN 45 | if (!x) { 46 | *b++ = '0'; 47 | *b = 0; 48 | goto done; 49 | } 50 | #endif 51 | s = s0 = dtoa(x, 2, precision, &decpt, &sign, &se); 52 | if (sign) 53 | *b++ = '-'; 54 | if (decpt == 9999) /* Infinity or Nan */ { 55 | while((*b++ = *s++)); 56 | /* "b" is used to calculate the return length. Decrement to exclude the 57 | * Null terminator from the length */ 58 | b--; 59 | goto done0; 60 | } 61 | if (decpt <= -4 || decpt > precision) { 62 | *b++ = *s++; 63 | if (*s) { 64 | *b++ = '.'; 65 | while((*b = *s++)) 66 | b++; 67 | } 68 | *b++ = 'e'; 69 | /* sprintf(b, "%+.2d", decpt - 1); */ 70 | if (--decpt < 0) { 71 | *b++ = '-'; 72 | decpt = -decpt; 73 | } 74 | else 75 | *b++ = '+'; 76 | for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10); 77 | for(;;) { 78 | i = decpt / k; 79 | *b++ = i + '0'; 80 | if (--j <= 0) 81 | break; 82 | decpt -= i*k; 83 | decpt *= 10; 84 | } 85 | *b = 0; 86 | } 87 | else if (decpt <= 0) { 88 | *b++ = '0'; 89 | *b++ = '.'; 90 | for(; decpt < 0; decpt++) 91 | *b++ = '0'; 92 | while((*b++ = *s++)); 93 | b--; 94 | } 95 | else { 96 | while((*b = *s++)) { 97 | b++; 98 | if (--decpt == 0 && *s) 99 | *b++ = '.'; 100 | } 101 | for(; decpt > 0; decpt--) 102 | *b++ = '0'; 103 | *b = 0; 104 | } 105 | done0: 106 | freedtoa(s0); 107 | #ifdef IGNORE_ZERO_SIGN 108 | done: 109 | #endif 110 | return b - b0; 111 | } 112 | -------------------------------------------------------------------------------- /src/simplex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "simplex.h" 3 | 4 | static int grad3[][3] = { 5 | {1,1,0}, {-1,1,0}, {1,-1,0}, {-1,-1,0}, 6 | {1,0,1}, {-1,0,1}, {1,0,-1}, {-1,0,-1}, 7 | {0,1,1}, {0,-1,1}, {0,1,-1}, {0,-1,-1}, 8 | }; 9 | 10 | static int p[] = { 11 | 155, 129, 111, 77, 237, 202, 100, 227, 53, 83, 226, 156, 115, 149, 93, 76, 12 | 116, 204, 1, 84, 186, 32, 114, 175, 136, 157, 50, 49, 14, 103, 10, 154, 13 | 236, 192, 167, 169, 159, 108, 119, 242, 231, 47, 144, 200, 42, 44, 110, 198, 14 | 59, 17, 122, 2, 145, 87, 209, 205, 72, 52, 13, 88, 64, 45, 245, 86, 15 | 30, 41, 67, 90, 151, 147, 140, 123, 38, 194, 134, 81, 184, 128, 6, 80, 16 | 255, 71, 20, 21, 172, 208, 65, 39, 235, 79, 254, 220, 54, 12, 180, 247, 17 | 105, 162, 16, 190, 191, 46, 96, 92, 4, 148, 56, 241, 171, 219, 234, 195, 18 | 19, 218, 101, 73, 201, 27, 107, 9, 85, 33, 215, 183, 112, 230, 253, 203, 19 | 118, 246, 31, 187, 207, 206, 224, 165, 48, 70, 251, 176, 109, 233, 26, 181, 20 | 37, 146, 69, 166, 24, 8, 214, 127, 82, 160, 120, 62, 212, 143, 28, 74, 21 | 91, 161, 133, 60, 152, 150, 168, 104, 25, 163, 57, 43, 238, 185, 131, 68, 22 | 117, 252, 174, 229, 124, 138, 63, 78, 225, 34, 216, 248, 164, 217, 211, 173, 23 | 89, 130, 197, 178, 232, 106, 95, 55, 223, 132, 58, 15, 188, 125, 153, 189, 24 | 139, 182, 141, 66, 244, 177, 137, 221, 61, 158, 213, 99, 5, 179, 240, 121, 25 | 228, 29, 22, 18, 113, 11, 51, 126, 35, 135, 222, 142, 94, 170, 249, 210, 26 | 98, 239, 102, 193, 199, 75, 243, 250, 97, 40, 23, 7, 0, 196, 36, 3, 27 | }; 28 | 29 | static int _floor(double x) { 30 | return x > 0 ? (int)x : (int)x - 1; 31 | } 32 | 33 | static double dot(int g[], double x, double y) { 34 | return g[0] * x + g[1] * y; 35 | } 36 | 37 | double simplex2d(double xin, double yin) { 38 | double n0, n1, n2; 39 | const double F2 = .5 * (sqrt(3.0) - 1.0); 40 | double s = (xin + yin) * F2; 41 | int i = floor(xin + s); 42 | int j = floor(yin + s); 43 | 44 | const double G2 = (3.0 - sqrt(3.0))/6.0; 45 | double t = (i + j) * G2; 46 | double X0 = i - t, 47 | Y0 = j - t; 48 | 49 | double x0 = xin - X0, 50 | y0 = yin - Y0; 51 | 52 | int i1, j1; 53 | if (x0 > y0) { 54 | i1 = 1; j1 = 0; 55 | } else { 56 | i1 = 0; j1 = 1; 57 | } 58 | 59 | double x1 = x0 - i1 + G2; 60 | double y1 = y0 - j1 + G2; 61 | double x2 = x0 - 1.0 + 2.0 * G2; 62 | double y2 = y0 - 1.0 + 2.0 * G2; 63 | 64 | int ii = i & 255; 65 | int jj = j & 255; 66 | 67 | int gi0 = p[(ii + p[jj]) % 256] % 12; 68 | int gi1 = p[(ii + i1 + p[(jj + j1) % 256]) % 256] % 12; 69 | int gi2 = p[(ii + 1 + p[(jj + 1) % 256]) % 256] % 12; 70 | 71 | double t0 = 0.5 - x0*x0 - y0*y0; 72 | if (t0 < 0) { 73 | n0 = 0.0; 74 | } else { 75 | t0 *= t0; 76 | n0 = t0 * t0 * dot(grad3[gi0], x0, y0); 77 | } 78 | 79 | double t1 = 0.5 - x1*x1 - y1*y1; 80 | if (t1 < 0) { 81 | n1 = 0.0; 82 | } else { 83 | t1 *= t1; 84 | n1 = t1 * t1 * dot(grad3[gi1], x1, y1); 85 | } 86 | 87 | double t2 = 0.5 - x2*x2 - y2*y2; 88 | if (t2 < 0) { 89 | n2 = 0.0; 90 | } else { 91 | t2 *= t2; 92 | n2 = t2 * t2 * dot(grad3[gi2], x2, y2); 93 | } 94 | 95 | return 70.0 * (n0 + n1 + n2); 96 | } 97 | -------------------------------------------------------------------------------- /src/input.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "input.h" 3 | 4 | namespace aroma { 5 | static const char* KEY_RELEASED_EVENT = "keyreleased"; 6 | static const char* KEY_PRESSED_EVENT = "keypressed"; 7 | 8 | InputHandler::InputHandler(LuaBinding* binding) : binding(binding) { 9 | for (int i = 32; i < 127; i++) { 10 | ascii_table[i - 32][0] = i; 11 | ascii_table[i - 32][1] = '\0'; 12 | } 13 | 14 | binding->bind_module(this); 15 | } 16 | 17 | void InputHandler::dispatch_key_event(const char* event_name, int key) { 18 | const char* name = key_name(key); 19 | 20 | // don't let key repeat send events when holding 21 | if (event_name == KEY_PRESSED_EVENT && 22 | keys_down.find(name) != keys_down.end()) 23 | { 24 | return; 25 | } 26 | 27 | lua_State* l = binding->lua(); 28 | int top = lua_gettop(l); 29 | binding->push_self(); 30 | 31 | if (event_name == KEY_RELEASED_EVENT) { 32 | keys_down.erase(name); 33 | } else if (event_name == KEY_PRESSED_EVENT) { 34 | keys_down.insert(name); 35 | } 36 | 37 | lua_pushstring(l, name); 38 | lua_pushnumber(l, key); 39 | binding->send_event(event_name, 2); 40 | 41 | lua_settop(l, top); 42 | } 43 | 44 | void InputHandler::key_down(int key) { 45 | dispatch_key_event(KEY_PRESSED_EVENT, key); 46 | } 47 | 48 | void InputHandler::key_up(int key) { 49 | dispatch_key_event(KEY_RELEASED_EVENT, key); 50 | } 51 | 52 | bool InputHandler::is_key_down(const char* name) { 53 | return keys_down.find(name) != keys_down.end(); 54 | } 55 | 56 | // TODO this is nacl specific right now, fix that 57 | const char* InputHandler::key_name(int key) { 58 | switch (key) { 59 | case 37: return "left"; 60 | case 38: return "up"; 61 | case 39: return "right"; 62 | case 40: return "down"; 63 | 64 | case 8: return "backspace"; 65 | case 9: return "tab"; 66 | 67 | case 13: return "return"; 68 | case 16: return "lshift"; 69 | case 17: return "lctrl"; 70 | case 18: return "lalt"; 71 | case 27: return "escape"; 72 | 73 | case 112: return "f1"; 74 | case 113: return "f2"; 75 | case 114: return "f3"; 76 | case 115: return "f4"; 77 | case 116: return "f5"; 78 | case 117: return "f6"; 79 | case 118: return "f7"; 80 | case 119: return "f8"; 81 | case 120: return "f9"; 82 | 83 | case 186: return ";"; 84 | case 187: return "="; 85 | case 188: return ","; 86 | case 189: return "-"; 87 | case 190: return "."; 88 | } 89 | 90 | if (key >= 32 && key <= 90) { 91 | if (key >= 'A' && key <= 'Z') key += 32; // make lowercase 92 | return ascii_table[key - 32]; 93 | } 94 | 95 | return "unknown"; 96 | } 97 | 98 | const char* InputHandler::module_name() { 99 | return "keyboard"; 100 | } 101 | 102 | void InputHandler::bind_all(lua_State* l) { 103 | set_new_func("isDown", _isDown); 104 | } 105 | 106 | int InputHandler::_isDown(lua_State* l) { 107 | InputHandler* self = upvalue_self(InputHandler); 108 | lua_pushboolean(l, self->is_key_down(luaL_checkstring(l, 1))); 109 | return 1; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** See Copyright Notice in lua.h 4 | */ 5 | 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | 11 | #include "lopcodes.h" 12 | 13 | 14 | /* ORDER OP */ 15 | 16 | const char *const luaP_opnames[NUM_OPCODES+1] = { 17 | "MOVE", 18 | "LOADK", 19 | "LOADBOOL", 20 | "LOADNIL", 21 | "GETUPVAL", 22 | "GETGLOBAL", 23 | "GETTABLE", 24 | "SETGLOBAL", 25 | "SETUPVAL", 26 | "SETTABLE", 27 | "NEWTABLE", 28 | "SELF", 29 | "ADD", 30 | "SUB", 31 | "MUL", 32 | "DIV", 33 | "MOD", 34 | "POW", 35 | "UNM", 36 | "NOT", 37 | "LEN", 38 | "CONCAT", 39 | "JMP", 40 | "EQ", 41 | "LT", 42 | "LE", 43 | "TEST", 44 | "TESTSET", 45 | "CALL", 46 | "TAILCALL", 47 | "RETURN", 48 | "FORLOOP", 49 | "FORPREP", 50 | "TFORLOOP", 51 | "SETLIST", 52 | "CLOSE", 53 | "CLOSURE", 54 | "VARARG", 55 | NULL 56 | }; 57 | 58 | 59 | #define opmode(t,a,b,c,m) (((t)<<7) | ((a)<<6) | ((b)<<4) | ((c)<<2) | (m)) 60 | 61 | const lu_byte luaP_opmodes[NUM_OPCODES] = { 62 | /* T A B C mode opcode */ 63 | opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_MOVE */ 64 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 65 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 66 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ 67 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 68 | ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_GETGLOBAL */ 69 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 70 | ,opmode(0, 0, OpArgK, OpArgN, iABx) /* OP_SETGLOBAL */ 71 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_SETUPVAL */ 72 | ,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_SETTABLE */ 73 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_NEWTABLE */ 74 | ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_SELF */ 75 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_ADD */ 76 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_SUB */ 77 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MUL */ 78 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_DIV */ 79 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_MOD */ 80 | ,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_POW */ 81 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_UNM */ 82 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_NOT */ 83 | ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LEN */ 84 | ,opmode(0, 1, OpArgR, OpArgR, iABC) /* OP_CONCAT */ 85 | ,opmode(0, 0, OpArgR, OpArgN, iAsBx) /* OP_JMP */ 86 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_EQ */ 87 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LT */ 88 | ,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_LE */ 89 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TEST */ 90 | ,opmode(1, 1, OpArgR, OpArgU, iABC) /* OP_TESTSET */ 91 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_CALL */ 92 | ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_TAILCALL */ 93 | ,opmode(0, 0, OpArgU, OpArgN, iABC) /* OP_RETURN */ 94 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORLOOP */ 95 | ,opmode(0, 1, OpArgR, OpArgN, iAsBx) /* OP_FORPREP */ 96 | ,opmode(1, 0, OpArgN, OpArgU, iABC) /* OP_TFORLOOP */ 97 | ,opmode(0, 0, OpArgU, OpArgU, iABC) /* OP_SETLIST */ 98 | ,opmode(0, 0, OpArgN, OpArgN, iABC) /* OP_CLOSE */ 99 | ,opmode(0, 1, OpArgU, OpArgN, iABx) /* OP_CLOSURE */ 100 | ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */ 101 | }; 102 | 103 | -------------------------------------------------------------------------------- /lib/ply.lua: -------------------------------------------------------------------------------- 1 | 2 | -- basic ply file parser 3 | 4 | module("ply", package.seeall) 5 | 6 | local function makeInserter(rows) 7 | return function(tbl, source) 8 | for _,c in ipairs(rows) do 9 | table.insert(tbl, source[c]) 10 | end 11 | end 12 | end 13 | 14 | local mesh_meta = { 15 | __index = { 16 | -- return array of vertices for all faces 17 | getVertices = function(self) 18 | local out = {} 19 | local insert = makeInserter{"x", "y", "z"} 20 | for _,f in ipairs(self.face) do 21 | for i = 2,4 do 22 | insert(out, self.vertex[f[i]+1]) 23 | end 24 | end 25 | return out 26 | end, 27 | -- return array of normals for face vertices 28 | getNormals = function(self) 29 | local out = {} 30 | local insert = makeInserter{"nx", "ny", "nz"} 31 | for _,f in ipairs(self.face) do 32 | for i = 2,4 do 33 | local v = self.vertex[f[i]+1] 34 | insert(out, v) 35 | end 36 | end 37 | return out 38 | end, 39 | } 40 | } 41 | 42 | function parse(fname) 43 | local lineNo = 0 44 | 45 | local elements = {} 46 | local element = nil 47 | local function header(line) 48 | if element then 49 | local ptype, pname = line:match("^property (%w+) (%w+)") 50 | if ptype then 51 | table.insert(element.properties, {type = ptype, name = pname}) 52 | else 53 | -- end of properties 54 | table.insert(elements, element) 55 | element = nil 56 | end 57 | end 58 | 59 | -- try to find a new element 60 | local etype, count = line:match("^element (%w+) (%d+)") 61 | if etype then 62 | element = { 63 | type = etype, 64 | count = tonumber(count), 65 | properties = {} 66 | } 67 | end 68 | 69 | if line == "end_header" then return true 70 | else return false end 71 | end 72 | 73 | local current = nil 74 | local final = {} 75 | local function data(line) 76 | local count = 0 77 | local set = {} 78 | 79 | local islist 80 | if #current.properties then 81 | islist = current.properties[1].type == "list" 82 | end 83 | 84 | for value in line:gmatch("(-?%d+%.?%d*)") do 85 | count = count + 1 86 | local fv = tonumber(value) 87 | 88 | if islist then table.insert(set, fv) 89 | else 90 | if not current.properties[count] then 91 | error("Too many values on line: "..lineNo) 92 | end 93 | 94 | set[current.properties[count].name] = fv 95 | end 96 | end 97 | 98 | -- not enough values 99 | if not islist and count < #current.properties then 100 | error("Too few values for property on line: "..lineNo) 101 | end 102 | 103 | table.insert(final[current.type], set) 104 | 105 | if #final[current.type] == current.count then 106 | current = table.remove(elements, nil) 107 | end 108 | 109 | return current == nil 110 | end 111 | 112 | local state = 0 -- 113 | for line in io.lines(fname) do 114 | lineNo = lineNo + 1 115 | if state == 0 then -- opening 116 | assert(line == "ply") 117 | state = 1 118 | elseif state == 1 then -- header 119 | local done = header(line) 120 | if done then 121 | -- create storage for final set 122 | for _,v in ipairs(elements) do 123 | final[v.type] = {} 124 | end 125 | 126 | current = table.remove(elements, 1) 127 | state = 2 128 | end 129 | elseif state == 2 then -- data 130 | data(line) 131 | end 132 | end 133 | 134 | setmetatable(final, mesh_meta) 135 | return final 136 | end 137 | 138 | 139 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # Aroma 2 | 3 | License (MIT) 4 | Copyright (C) 2012 by Leaf Corcoran 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | # Lua 5.1.2 25 | 26 | Copyright (C) 1994-2012 Lua.org, PUC-Rio. 27 | 28 | Permission is hereby granted, free of charge, to any person obtaining a copy 29 | of this software and associated documentation files (the "Software"), to deal 30 | in the Software without restriction, including without limitation the rights 31 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 32 | copies of the Software, and to permit persons to whom the Software is 33 | furnished to do so, subject to the following conditions: 34 | 35 | The above copyright notice and this permission notice shall be included in 36 | all copies or substantial portions of the Software. 37 | 38 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 39 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 40 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 41 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 42 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 43 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 44 | THE SOFTWARE. 45 | 46 | # Lua CJSON 47 | 48 | Copyright (c) 2010-2012 Mark Pulford 49 | 50 | Permission is hereby granted, free of charge, to any person obtaining 51 | a copy of this software and associated documentation files (the 52 | "Software"), to deal in the Software without restriction, including 53 | without limitation the rights to use, copy, modify, merge, publish, 54 | distribute, sublicense, and/or sell copies of the Software, and to 55 | permit persons to whom the Software is furnished to do so, subject to 56 | the following conditions: 57 | 58 | The above copyright notice and this permission notice shall be 59 | included in all copies or substantial portions of the Software. 60 | 61 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 62 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 63 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 64 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 65 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 66 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 67 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/renderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "context.h" 4 | #include "lua_binding.h" 5 | #include "geometry.h" 6 | #include "shader.h" 7 | #include "image.h" 8 | #include "font.h" 9 | 10 | namespace aroma { 11 | const static double FPS_UPDATE_FREQ = 1.0; 12 | 13 | struct TexQuadCoords { 14 | GLfloat coords[16]; 15 | static TexQuadCoords from_rect(float x, float y, float w, float h, 16 | float sx, float sy, float sw, float sh); 17 | 18 | static TexQuadCoords from_rect(float x, float y, float w, float h, 19 | const Image & img, float tx, float ty, float tw, float th); 20 | }; 21 | 22 | struct QuadCoords { 23 | GLfloat coords[8]; 24 | static QuadCoords from_rect(float x, float y, float w, float h); 25 | }; 26 | 27 | struct Quad { 28 | double x1, y1, x2, y2; 29 | 30 | double width() const; 31 | double height() const; 32 | 33 | QuadCoords quad_coords() const; 34 | 35 | static int _new(lua_State* l); 36 | static int _flip(lua_State* l); 37 | 38 | int push(lua_State* l); 39 | }; 40 | 41 | // the transformation used by draw and drawq 42 | struct Transform { 43 | double x, y, r, sx, sy, ox, oy; 44 | 45 | bool needs_mat() const; 46 | void push(MatrixStack& proj) const; 47 | 48 | void print() const; 49 | 50 | static Transform read(lua_State* l, int i); 51 | }; 52 | 53 | class Renderer : public Bindable { 54 | protected: 55 | GLContext* context; 56 | LuaBinding* binding; 57 | Shader* default_shader; 58 | Font* current_font; 59 | 60 | double last_time; 61 | bool _texturing; 62 | MatrixStack projection; 63 | 64 | GLuint quad_buffer; 65 | GLuint tex_quad_buffer; 66 | GLuint coord_buffer; 67 | 68 | // for fps calculation 69 | int fps; 70 | int frames; 71 | double elapsed_time; 72 | 73 | // draw untextured vertices that are bound to current buffer 74 | void draw_primitive(GLenum type=GL_TRIANGLE_STRIP, 75 | size_t vertices=4); 76 | 77 | public: 78 | Color current_color; 79 | 80 | Renderer(GLContext* context, LuaBinding* binding); 81 | 82 | bool init(); 83 | void draw(double dt); 84 | void tick(); 85 | 86 | void reshape(const int w, const int h); 87 | 88 | void rect(float x1, float y1, float w, float h); 89 | void rect_line(float x1, float y1, float w, float h); 90 | 91 | void img_rect(const Image* i, const Transform& t); 92 | void img_rect_blit(const Image* i, const Quad& q, const Transform& t); 93 | void font_write(const Font* font, int x, int y, const char *str); 94 | 95 | void texturing(bool enabled); 96 | 97 | GLContext* get_context(); 98 | int get_fps(); 99 | 100 | void bind_all(lua_State *l); 101 | const char* module_name(); 102 | 103 | static int _setColor(lua_State* l); 104 | static int _getColor(lua_State* l); 105 | 106 | static int _setBackgroundColor(lua_State* l); 107 | 108 | static int _getWidth(lua_State* l); 109 | static int _getHeight(lua_State* l); 110 | 111 | static int _reset(lua_State *l); 112 | 113 | static int _rectangle(lua_State *l); 114 | static int _draw(lua_State *l); 115 | static int _drawq(lua_State *l); 116 | 117 | static int _push(lua_State* l); 118 | static int _pop(lua_State* l); 119 | static int _translate(lua_State* l); 120 | static int _scale(lua_State* l); 121 | static int _rotate(lua_State* l); 122 | 123 | static int _setDefaultShader(lua_State *l); 124 | 125 | static int _setFont(lua_State *l); 126 | static int _getFont(lua_State *l); 127 | 128 | static int _setLineWidth(lua_State *l); 129 | 130 | static int _print(lua_State* l); 131 | }; 132 | } 133 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** String table (keeps all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #include 9 | 10 | #define lstring_c 11 | #define LUA_CORE 12 | 13 | #include "lua.h" 14 | 15 | #include "lmem.h" 16 | #include "lobject.h" 17 | #include "lstate.h" 18 | #include "lstring.h" 19 | 20 | 21 | 22 | void luaS_resize (lua_State *L, int newsize) { 23 | GCObject **newhash; 24 | stringtable *tb; 25 | int i; 26 | if (G(L)->gcstate == GCSsweepstring) 27 | return; /* cannot resize during GC traverse */ 28 | newhash = luaM_newvector(L, newsize, GCObject *); 29 | tb = &G(L)->strt; 30 | for (i=0; isize; i++) { 33 | GCObject *p = tb->hash[i]; 34 | while (p) { /* for each node in the list */ 35 | GCObject *next = p->gch.next; /* save next */ 36 | unsigned int h = gco2ts(p)->hash; 37 | int h1 = lmod(h, newsize); /* new position */ 38 | lua_assert(cast_int(h%newsize) == lmod(h, newsize)); 39 | p->gch.next = newhash[h1]; /* chain it */ 40 | newhash[h1] = p; 41 | p = next; 42 | } 43 | } 44 | luaM_freearray(L, tb->hash, tb->size, TString *); 45 | tb->size = newsize; 46 | tb->hash = newhash; 47 | } 48 | 49 | 50 | static TString *newlstr (lua_State *L, const char *str, size_t l, 51 | unsigned int h) { 52 | TString *ts; 53 | stringtable *tb; 54 | if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char)) 55 | luaM_toobig(L); 56 | ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString))); 57 | ts->tsv.len = l; 58 | ts->tsv.hash = h; 59 | ts->tsv.marked = luaC_white(G(L)); 60 | ts->tsv.tt = LUA_TSTRING; 61 | ts->tsv.reserved = 0; 62 | memcpy(ts+1, str, l*sizeof(char)); 63 | ((char *)(ts+1))[l] = '\0'; /* ending 0 */ 64 | tb = &G(L)->strt; 65 | h = lmod(h, tb->size); 66 | ts->tsv.next = tb->hash[h]; /* chain new entry */ 67 | tb->hash[h] = obj2gco(ts); 68 | tb->nuse++; 69 | if (tb->nuse > cast(lu_int32, tb->size) && tb->size <= MAX_INT/2) 70 | luaS_resize(L, tb->size*2); /* too crowded */ 71 | return ts; 72 | } 73 | 74 | 75 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 76 | GCObject *o; 77 | unsigned int h = cast(unsigned int, l); /* seed */ 78 | size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ 79 | size_t l1; 80 | for (l1=l; l1>=step; l1-=step) /* compute hash */ 81 | h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1])); 82 | for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)]; 83 | o != NULL; 84 | o = o->gch.next) { 85 | TString *ts = rawgco2ts(o); 86 | if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) { 87 | /* string may be dead */ 88 | if (isdead(G(L), o)) changewhite(o); 89 | return ts; 90 | } 91 | } 92 | return newlstr(L, str, l, h); /* not found */ 93 | } 94 | 95 | 96 | Udata *luaS_newudata (lua_State *L, size_t s, Table *e) { 97 | Udata *u; 98 | if (s > MAX_SIZET - sizeof(Udata)) 99 | luaM_toobig(L); 100 | u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata))); 101 | u->uv.marked = luaC_white(G(L)); /* is not finalized */ 102 | u->uv.tt = LUA_TUSERDATA; 103 | u->uv.len = s; 104 | u->uv.metatable = NULL; 105 | u->uv.env = e; 106 | /* chain it on udata list (after main thread) */ 107 | u->uv.next = G(L)->mainthread->next; 108 | G(L)->mainthread->next = obj2gco(u); 109 | return u; 110 | } 111 | 112 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h,v 2.15.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Garbage Collector 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lgc_h 8 | #define lgc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | ** Possible states of the Garbage Collector 16 | */ 17 | #define GCSpause 0 18 | #define GCSpropagate 1 19 | #define GCSsweepstring 2 20 | #define GCSsweep 3 21 | #define GCSfinalize 4 22 | 23 | 24 | /* 25 | ** some userful bit tricks 26 | */ 27 | #define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) 28 | #define setbits(x,m) ((x) |= (m)) 29 | #define testbits(x,m) ((x) & (m)) 30 | #define bitmask(b) (1<<(b)) 31 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 32 | #define l_setbit(x,b) setbits(x, bitmask(b)) 33 | #define resetbit(x,b) resetbits(x, bitmask(b)) 34 | #define testbit(x,b) testbits(x, bitmask(b)) 35 | #define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) 36 | #define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) 37 | #define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) 38 | 39 | 40 | 41 | /* 42 | ** Layout for bit use in `marked' field: 43 | ** bit 0 - object is white (type 0) 44 | ** bit 1 - object is white (type 1) 45 | ** bit 2 - object is black 46 | ** bit 3 - for userdata: has been finalized 47 | ** bit 3 - for tables: has weak keys 48 | ** bit 4 - for tables: has weak values 49 | ** bit 5 - object is fixed (should not be collected) 50 | ** bit 6 - object is "super" fixed (only the main thread) 51 | */ 52 | 53 | 54 | #define WHITE0BIT 0 55 | #define WHITE1BIT 1 56 | #define BLACKBIT 2 57 | #define FINALIZEDBIT 3 58 | #define KEYWEAKBIT 3 59 | #define VALUEWEAKBIT 4 60 | #define FIXEDBIT 5 61 | #define SFIXEDBIT 6 62 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 63 | 64 | 65 | #define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) 66 | #define isblack(x) testbit((x)->gch.marked, BLACKBIT) 67 | #define isgray(x) (!isblack(x) && !iswhite(x)) 68 | 69 | #define otherwhite(g) (g->currentwhite ^ WHITEBITS) 70 | #define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) 71 | 72 | #define changewhite(x) ((x)->gch.marked ^= WHITEBITS) 73 | #define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) 74 | 75 | #define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) 76 | 77 | #define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) 78 | 79 | 80 | #define luaC_checkGC(L) { \ 81 | condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ 82 | if (G(L)->totalbytes >= G(L)->GCthreshold) \ 83 | luaC_step(L); } 84 | 85 | 86 | #define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ 87 | luaC_barrierf(L,obj2gco(p),gcvalue(v)); } 88 | 89 | #define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ 90 | luaC_barrierback(L,t); } 91 | 92 | #define luaC_objbarrier(L,p,o) \ 93 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ 94 | luaC_barrierf(L,obj2gco(p),obj2gco(o)); } 95 | 96 | #define luaC_objbarriert(L,t,o) \ 97 | { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } 98 | 99 | LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); 100 | LUAI_FUNC void luaC_callGCTM (lua_State *L); 101 | LUAI_FUNC void luaC_freeall (lua_State *L); 102 | LUAI_FUNC void luaC_step (lua_State *L); 103 | LUAI_FUNC void luaC_fullgc (lua_State *L); 104 | LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); 105 | LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); 106 | LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); 107 | LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); 108 | 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/src/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c,v 2.8.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** save precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #include 8 | 9 | #define ldump_c 10 | #define LUA_CORE 11 | 12 | #include "lua.h" 13 | 14 | #include "lobject.h" 15 | #include "lstate.h" 16 | #include "lundump.h" 17 | 18 | typedef struct { 19 | lua_State* L; 20 | lua_Writer writer; 21 | void* data; 22 | int strip; 23 | int status; 24 | } DumpState; 25 | 26 | #define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) 27 | #define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) 28 | 29 | static void DumpBlock(const void* b, size_t size, DumpState* D) 30 | { 31 | if (D->status==0) 32 | { 33 | lua_unlock(D->L); 34 | D->status=(*D->writer)(D->L,b,size,D->data); 35 | lua_lock(D->L); 36 | } 37 | } 38 | 39 | static void DumpChar(int y, DumpState* D) 40 | { 41 | char x=(char)y; 42 | DumpVar(x,D); 43 | } 44 | 45 | static void DumpInt(int x, DumpState* D) 46 | { 47 | DumpVar(x,D); 48 | } 49 | 50 | static void DumpNumber(lua_Number x, DumpState* D) 51 | { 52 | DumpVar(x,D); 53 | } 54 | 55 | static void DumpVector(const void* b, int n, size_t size, DumpState* D) 56 | { 57 | DumpInt(n,D); 58 | DumpMem(b,n,size,D); 59 | } 60 | 61 | static void DumpString(const TString* s, DumpState* D) 62 | { 63 | if (s==NULL || getstr(s)==NULL) 64 | { 65 | size_t size=0; 66 | DumpVar(size,D); 67 | } 68 | else 69 | { 70 | size_t size=s->tsv.len+1; /* include trailing '\0' */ 71 | DumpVar(size,D); 72 | DumpBlock(getstr(s),size,D); 73 | } 74 | } 75 | 76 | #define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) 77 | 78 | static void DumpFunction(const Proto* f, const TString* p, DumpState* D); 79 | 80 | static void DumpConstants(const Proto* f, DumpState* D) 81 | { 82 | int i,n=f->sizek; 83 | DumpInt(n,D); 84 | for (i=0; ik[i]; 87 | DumpChar(ttype(o),D); 88 | switch (ttype(o)) 89 | { 90 | case LUA_TNIL: 91 | break; 92 | case LUA_TBOOLEAN: 93 | DumpChar(bvalue(o),D); 94 | break; 95 | case LUA_TNUMBER: 96 | DumpNumber(nvalue(o),D); 97 | break; 98 | case LUA_TSTRING: 99 | DumpString(rawtsvalue(o),D); 100 | break; 101 | default: 102 | lua_assert(0); /* cannot happen */ 103 | break; 104 | } 105 | } 106 | n=f->sizep; 107 | DumpInt(n,D); 108 | for (i=0; ip[i],f->source,D); 109 | } 110 | 111 | static void DumpDebug(const Proto* f, DumpState* D) 112 | { 113 | int i,n; 114 | n= (D->strip) ? 0 : f->sizelineinfo; 115 | DumpVector(f->lineinfo,n,sizeof(int),D); 116 | n= (D->strip) ? 0 : f->sizelocvars; 117 | DumpInt(n,D); 118 | for (i=0; ilocvars[i].varname,D); 121 | DumpInt(f->locvars[i].startpc,D); 122 | DumpInt(f->locvars[i].endpc,D); 123 | } 124 | n= (D->strip) ? 0 : f->sizeupvalues; 125 | DumpInt(n,D); 126 | for (i=0; iupvalues[i],D); 127 | } 128 | 129 | static void DumpFunction(const Proto* f, const TString* p, DumpState* D) 130 | { 131 | DumpString((f->source==p || D->strip) ? NULL : f->source,D); 132 | DumpInt(f->linedefined,D); 133 | DumpInt(f->lastlinedefined,D); 134 | DumpChar(f->nups,D); 135 | DumpChar(f->numparams,D); 136 | DumpChar(f->is_vararg,D); 137 | DumpChar(f->maxstacksize,D); 138 | DumpCode(f,D); 139 | DumpConstants(f,D); 140 | DumpDebug(f,D); 141 | } 142 | 143 | static void DumpHeader(DumpState* D) 144 | { 145 | char h[LUAC_HEADERSIZE]; 146 | luaU_header(h); 147 | DumpBlock(h,LUAC_HEADERSIZE,D); 148 | } 149 | 150 | /* 151 | ** dump Lua function as precompiled chunk 152 | */ 153 | int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) 154 | { 155 | DumpState D; 156 | D.L=L; 157 | D.writer=w; 158 | D.data=data; 159 | D.strip=strip; 160 | D.status=0; 161 | DumpHeader(&D); 162 | DumpFunction(f,NULL,&D); 163 | return D.status; 164 | } 165 | -------------------------------------------------------------------------------- /src/lua_binding.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "lua_binding.h" 3 | #include "renderer.h" 4 | 5 | namespace aroma { 6 | static const char* AROMA_NAME = "aroma"; 7 | 8 | LuaBinding::LuaBinding() : game_thread(NULL) { 9 | l = luaL_newstate(); 10 | luaL_openlibs(l); 11 | log("created a lua\n"); 12 | } 13 | 14 | bool LuaBinding::bind_all() { 15 | lua_newtable(l); 16 | lua_setglobal(l, AROMA_NAME); 17 | 18 | return true; 19 | } 20 | 21 | void LuaBinding::bind_module(Bindable *b) { 22 | lua_getglobal(l, AROMA_NAME); 23 | lua_newtable(l); 24 | int i = lua_gettop(l); 25 | b->bind_all(l); 26 | lua_settop(l, i); 27 | lua_setfield(l, -2, b->module_name()); 28 | } 29 | 30 | lua_State* LuaBinding::lua() { 31 | return l; 32 | } 33 | 34 | void LuaBinding::push_self() { 35 | lua_getglobal(l, AROMA_NAME); 36 | } 37 | 38 | // takes value on top of stack and puts it in package.loaded[name] 39 | // pops value 40 | void LuaBinding::preload_library(const char* name) { 41 | int i = lua_gettop(l); 42 | lua_getglobal(l, "package"); 43 | lua_getfield(l, -1, "loaded"); 44 | lua_pushvalue(l, i); 45 | lua_setfield(l, -2, name); 46 | lua_settop(l, i - 1); 47 | } 48 | 49 | void LuaBinding::set_game_thread(lua_State* thread) { 50 | game_thread = thread; 51 | } 52 | 53 | void LuaBinding::send_event(const char* name, int nargs) { 54 | if (!game_thread) return; 55 | 56 | lua_pushstring(game_thread, name); 57 | lua_xmove(l, game_thread, nargs); 58 | int status = lua_resume(game_thread, nargs + 1); 59 | 60 | if (status != 0 && status != LUA_YIELD) { 61 | handle_error(game_thread, name); 62 | game_thread = NULL; 63 | return; 64 | } 65 | 66 | lua_settop(game_thread, 0); // don't care! 67 | } 68 | 69 | void LuaBinding::handle_error(lua_State *thread, const char* name) { 70 | err("event `%s` failed:\n", name); 71 | stack_dump(thread); 72 | } 73 | 74 | bool LuaBinding::load_and_run(void* buffer, size_t buff_len, const char* name) { 75 | if (luaL_loadbuffer(l, (const char*)buffer, buff_len, name) != 0) { 76 | err("%s\n", luaL_checkstring(l, -1)); 77 | return false; 78 | } 79 | 80 | if (lua_pcall(l, 0, 0, 0) != 0) { 81 | err("%s\n", luaL_checkstring(l, -1)); 82 | return false; 83 | } 84 | 85 | return true; 86 | } 87 | 88 | // check if the ith item on the stack has metatable called type 89 | bool LuaBinding::is_type(lua_State* l, int i, const char* type) { 90 | int top = lua_gettop(l); 91 | lua_getmetatable(l, i); 92 | lua_getfield(l, LUA_REGISTRYINDEX, type); 93 | bool eq = (bool)lua_rawequal(l, -1, -2); 94 | lua_settop(l, top); 95 | return eq; 96 | } 97 | 98 | // store something in the registry to prevent it from being garbage collected 99 | void LuaBinding::store_in_registry(lua_State *l, int i, const char* name) { 100 | luaL_newmetatable(l, AROMA_NAME); 101 | lua_pushvalue(l, 1); 102 | lua_setfield(l, -2, name); 103 | lua_pop(l, 1); // pop metatable 104 | } 105 | 106 | // get something stored in registry 107 | int LuaBinding::from_registry(lua_State *l, const char* name) { 108 | luaL_newmetatable(l, AROMA_NAME); 109 | lua_getfield(l, -1, name); 110 | lua_remove(l, -2); 111 | return 1; 112 | } 113 | 114 | // got this someplace off lua wiki/mailing list 115 | void stack_dump(lua_State *L) { 116 | int i; 117 | int top = lua_gettop(L); 118 | for (i = 1; i <= top; i++) { /* repeat for each level */ 119 | printf("%d: ", i); 120 | int t = lua_type(L, i); 121 | switch (t) { 122 | case LUA_TSTRING: /* strings */ 123 | printf("`%s'", lua_tostring(L, i)); 124 | break; 125 | 126 | case LUA_TBOOLEAN: /* booleans */ 127 | printf(lua_toboolean(L, i) ? "true" : "false"); 128 | break; 129 | 130 | case LUA_TNUMBER: /* numbers */ 131 | printf("%g", lua_tonumber(L, i)); 132 | break; 133 | 134 | default: /* other values */ 135 | printf("%s", lua_typename(L, t)); 136 | break; 137 | 138 | } 139 | printf("\n"); /* put a separator */ 140 | } 141 | printf("\n"); /* end the listing */ 142 | } 143 | 144 | } 145 | 146 | -------------------------------------------------------------------------------- /src/framebuffer.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "framebuffer.h" 3 | 4 | namespace aroma { 5 | 6 | void register_Framebuffer(lua_State *l) { 7 | setfunction("framebuffer", FrameBuffer::_new); 8 | } 9 | 10 | int FrameBuffer::_new(lua_State *l) { 11 | int width = luaL_checkinteger(l, -2); 12 | int height = luaL_checkinteger(l, -1); 13 | 14 | FrameBuffer *self = newuserdata(FrameBuffer); 15 | cout << "creating framebuffer " << $(width) << $(height) << endl; 16 | self->width = width; 17 | self->height = height; 18 | self->tex = Image::from_bytes(NULL, width, height); 19 | 20 | glGenFramebuffersEXT(1, &self->fbo); 21 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self->fbo); 22 | 23 | // attach texture to fbo 24 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, 25 | GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 26 | self->tex.texid, 0); 27 | 28 | // create depth buffer 29 | glGenRenderbuffersEXT(1, &self->depth); 30 | glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, self->depth); 31 | glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, 32 | GL_DEPTH_COMPONENT24, width, height); 33 | 34 | // attach depth to fbo 35 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, 36 | GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, self->depth); 37 | 38 | // see if it worked 39 | GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 40 | if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { 41 | cout << "Failed to setup framebuffer" << endl; 42 | } 43 | 44 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 45 | 46 | if (luaL_newmetatable(l, "FrameBuffer")) { 47 | lua_newtable(l); // the index table 48 | setfunction("bind", FrameBuffer::_bind); 49 | setfunction("release", FrameBuffer::_release); 50 | setfunction("render", FrameBuffer::_render); 51 | setfunction("bindTex", FrameBuffer::_bindTex); 52 | setfunction("draw", FrameBuffer::_draw); 53 | 54 | lua_setfield(l, -2, "__index"); 55 | } 56 | lua_setmetatable(l, -2); 57 | 58 | return 1; 59 | } 60 | 61 | int FrameBuffer::_render(lua_State *l) { 62 | FrameBuffer *self = getself(FrameBuffer); 63 | 64 | lua_pushvalue(l, 2); // make sure the function is on top 65 | lua_pushinteger(l, self->width); 66 | lua_pushinteger(l, self->height); 67 | 68 | 69 | glPushAttrib(GL_VIEWPORT_BIT); 70 | glViewport(0, 0, self->width, self->height); 71 | 72 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self->fbo); 73 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // don't do this 74 | 75 | glMatrixMode(GL_PROJECTION); 76 | glPushMatrix(); 77 | glLoadIdentity(); 78 | gluOrtho2D(0, self->width, self->height, 0); 79 | glMatrixMode(GL_MODELVIEW); 80 | glLoadIdentity(); 81 | 82 | lua_call(l, 2, 0); 83 | 84 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 85 | 86 | glMatrixMode(GL_PROJECTION); 87 | glPopMatrix(); 88 | glMatrixMode(GL_MODELVIEW); 89 | 90 | glPopAttrib(); 91 | 92 | return 0; 93 | } 94 | 95 | int FrameBuffer::_bind(lua_State *l) { 96 | FrameBuffer *self = getself(FrameBuffer); 97 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, self->fbo); 98 | return 0; 99 | } 100 | 101 | int FrameBuffer::_release(lua_State *l) { 102 | glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 103 | return 0; 104 | } 105 | 106 | int FrameBuffer::_bindTex(lua_State *l) { 107 | FrameBuffer *self = getself(FrameBuffer); 108 | self->tex.bind(); 109 | return 0; 110 | } 111 | 112 | int FrameBuffer::_draw(lua_State *l) { 113 | FrameBuffer *self = getself(FrameBuffer); 114 | 115 | Point size = {self->width, self->height}; 116 | if (lua_gettop(l) == 5) { size = Point::pop(l); } 117 | Point origin = Point::pop(l); 118 | 119 | // self->tex.draw(p.x, p.y); // this is upside down 120 | glBindTexture(GL_TEXTURE_2D, self->tex.texid); 121 | glEnable(GL_TEXTURE_2D); 122 | glBegin(GL_QUADS); 123 | glTexCoord2f(0, 1); 124 | glVertex2d(origin.x, origin.y); 125 | glTexCoord2f(1, 1); 126 | glVertex2d(origin.x + size.x, origin.y); 127 | glTexCoord2f(1, 0); 128 | glVertex2d(origin.x + size.x, origin.y + size.y); 129 | glTexCoord2f(0, 0); 130 | glVertex2d(origin.x, origin.y + size.y); 131 | glEnd(); 132 | 133 | return 0; 134 | } 135 | 136 | } 137 | 138 | -------------------------------------------------------------------------------- /nacl/lua-5.1.5/Makefile: -------------------------------------------------------------------------------- 1 | # makefile for installing Lua 2 | # see INSTALL for installation instructions 3 | # see src/Makefile and src/luaconf.h for further customization 4 | 5 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= 6 | 7 | # Your platform. See PLATS for possible values. 8 | PLAT= none 9 | 10 | # Where to install. The installation starts in the src and doc directories, 11 | # so take care if INSTALL_TOP is not an absolute path. 12 | INSTALL_TOP= /usr/local 13 | INSTALL_BIN= $(INSTALL_TOP)/bin 14 | INSTALL_INC= $(INSTALL_TOP)/include 15 | INSTALL_LIB= $(INSTALL_TOP)/lib 16 | INSTALL_MAN= $(INSTALL_TOP)/man/man1 17 | # 18 | # You probably want to make INSTALL_LMOD and INSTALL_CMOD consistent with 19 | # LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h (and also with etc/lua.pc). 20 | INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V 21 | INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V 22 | 23 | # How to install. If your install program does not support "-p", then you 24 | # may have to run ranlib on the installed liblua.a (do "make ranlib"). 25 | INSTALL= install -p 26 | INSTALL_EXEC= $(INSTALL) -m 0755 27 | INSTALL_DATA= $(INSTALL) -m 0644 28 | # 29 | # If you don't have install you can use cp instead. 30 | # INSTALL= cp -p 31 | # INSTALL_EXEC= $(INSTALL) 32 | # INSTALL_DATA= $(INSTALL) 33 | 34 | # Utilities. 35 | MKDIR= mkdir -p 36 | RANLIB= ranlib 37 | 38 | # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= 39 | 40 | # Convenience platforms targets. 41 | PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris 42 | 43 | # What to install. 44 | TO_BIN= lua luac 45 | TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp 46 | TO_LIB= liblua.a 47 | TO_MAN= lua.1 luac.1 48 | 49 | # Lua version and release. 50 | V= 5.1 51 | R= 5.1.5 52 | 53 | all: $(PLAT) 54 | 55 | $(PLATS) clean: 56 | cd src && $(MAKE) $@ 57 | 58 | test: dummy 59 | src/lua test/hello.lua 60 | 61 | install: dummy 62 | cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD) 63 | cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) 64 | cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) 65 | cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) 66 | cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) 67 | 68 | ranlib: 69 | cd src && cd $(INSTALL_LIB) && $(RANLIB) $(TO_LIB) 70 | 71 | local: 72 | $(MAKE) install INSTALL_TOP=.. 73 | 74 | none: 75 | @echo "Please do" 76 | @echo " make PLATFORM" 77 | @echo "where PLATFORM is one of these:" 78 | @echo " $(PLATS)" 79 | @echo "See INSTALL for complete instructions." 80 | 81 | # make may get confused with test/ and INSTALL in a case-insensitive OS 82 | dummy: 83 | 84 | # echo config parameters 85 | echo: 86 | @echo "" 87 | @echo "These are the parameters currently set in src/Makefile to build Lua $R:" 88 | @echo "" 89 | @cd src && $(MAKE) -s echo 90 | @echo "" 91 | @echo "These are the parameters currently set in Makefile to install Lua $R:" 92 | @echo "" 93 | @echo "PLAT = $(PLAT)" 94 | @echo "INSTALL_TOP = $(INSTALL_TOP)" 95 | @echo "INSTALL_BIN = $(INSTALL_BIN)" 96 | @echo "INSTALL_INC = $(INSTALL_INC)" 97 | @echo "INSTALL_LIB = $(INSTALL_LIB)" 98 | @echo "INSTALL_MAN = $(INSTALL_MAN)" 99 | @echo "INSTALL_LMOD = $(INSTALL_LMOD)" 100 | @echo "INSTALL_CMOD = $(INSTALL_CMOD)" 101 | @echo "INSTALL_EXEC = $(INSTALL_EXEC)" 102 | @echo "INSTALL_DATA = $(INSTALL_DATA)" 103 | @echo "" 104 | @echo "See also src/luaconf.h ." 105 | @echo "" 106 | 107 | # echo private config parameters 108 | pecho: 109 | @echo "V = $(V)" 110 | @echo "R = $(R)" 111 | @echo "TO_BIN = $(TO_BIN)" 112 | @echo "TO_INC = $(TO_INC)" 113 | @echo "TO_LIB = $(TO_LIB)" 114 | @echo "TO_MAN = $(TO_MAN)" 115 | 116 | # echo config parameters as Lua code 117 | # uncomment the last sed expression if you want nil instead of empty strings 118 | lecho: 119 | @echo "-- installation parameters for Lua $R" 120 | @echo "VERSION = '$V'" 121 | @echo "RELEASE = '$R'" 122 | @$(MAKE) echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/' 123 | @echo "-- EOF" 124 | 125 | # list targets that do not create files (but not all makes understand .PHONY) 126 | .PHONY: all $(PLATS) clean test install local none dummy echo pecho lecho 127 | 128 | # (end of Makefile) 129 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/Makefile: -------------------------------------------------------------------------------- 1 | ##### Available defines for CJSON_CFLAGS ##### 2 | ## 3 | ## USE_INTERNAL_ISINF: Workaround for Solaris platforms missing isinf(). 4 | ## DISABLE_INVALID_NUMBERS: Permanently disable invalid JSON numbers: 5 | ## NaN, Infinity, hex. 6 | ## 7 | ## Optional built-in number conversion uses the following defines: 8 | ## USE_INTERNAL_FPCONV: Use builtin strtod/dtoa for numeric conversions. 9 | ## IEEE_BIG_ENDIAN: Required on big endian architectures. 10 | ## MULTIPLE_THREADS: Must be set when Lua CJSON may be used in a 11 | ## multi-threaded application. Requries _pthreads_. 12 | 13 | ##### Build defaults ##### 14 | LUA_VERSION = 5.1 15 | TARGET = cjson.so 16 | PREFIX = /usr/local 17 | #CFLAGS = -g -Wall -pedantic -fno-inline 18 | CFLAGS = -O3 -Wall -pedantic -DNDEBUG 19 | CJSON_CFLAGS = -fpic 20 | CJSON_LDFLAGS = -shared 21 | LUA_INCLUDE_DIR = $(PREFIX)/include 22 | LUA_CMODULE_DIR = $(PREFIX)/lib/lua/$(LUA_VERSION) 23 | LUA_MODULE_DIR = $(PREFIX)/share/lua/$(LUA_VERSION) 24 | LUA_BIN_DIR = $(PREFIX)/bin 25 | 26 | ##### Platform overrides ##### 27 | ## 28 | ## Tweak one of the platform sections below to suit your situation. 29 | ## 30 | ## See http://lua-users.org/wiki/BuildingModules for further platform 31 | ## specific details. 32 | 33 | ## Linux 34 | 35 | ## FreeBSD 36 | #LUA_INCLUDE_DIR = $(PREFIX)/include/lua51 37 | 38 | ## MacOSX (Macports) 39 | #PREFIX = /opt/local 40 | #CJSON_LDFLAGS = -bundle -undefined dynamic_lookup 41 | 42 | ## Solaris 43 | #CC = gcc 44 | #CJSON_CFLAGS = -fpic -DUSE_INTERNAL_ISINF 45 | 46 | ## Windows (MinGW) 47 | #TARGET = cjson.dll 48 | #PREFIX = /home/user/opt 49 | #CJSON_CFLAGS = -DDISABLE_INVALID_NUMBERS 50 | #CJSON_LDFLAGS = -shared -L$(PREFIX)/lib -llua51 51 | #LUA_BIN_SUFFIX = .lua 52 | 53 | ##### Number conversion configuration ##### 54 | 55 | ## Use Libc support for number conversion (default) 56 | FPCONV_OBJS = fpconv.o 57 | 58 | ## Use built in number conversion 59 | #FPCONV_OBJS = g_fmt.o dtoa.o 60 | #CJSON_CFLAGS += -DUSE_INTERNAL_FPCONV 61 | 62 | ## Compile built in number conversion for big endian architectures 63 | #CJSON_CFLAGS += -DIEEE_BIG_ENDIAN 64 | 65 | ## Compile built in number conversion to support multi-threaded 66 | ## applications (recommended) 67 | #CJSON_CFLAGS += -pthread -DMULTIPLE_THREADS 68 | #CJSON_LDFLAGS += -pthread 69 | 70 | ##### End customisable sections ##### 71 | 72 | TEST_FILES = README bench.lua genutf8.pl test.lua octets-escaped.dat \ 73 | example1.json example2.json example3.json example4.json \ 74 | example5.json numbers.json rfc-example1.json \ 75 | rfc-example2.json types.json 76 | DATAPERM = 644 77 | EXECPERM = 755 78 | 79 | ASCIIDOC = asciidoc 80 | 81 | BUILD_CFLAGS = -I$(LUA_INCLUDE_DIR) $(CJSON_CFLAGS) 82 | OBJS = lua_cjson.o strbuf.o $(FPCONV_OBJS) 83 | 84 | .PHONY: all clean install install-extra doc 85 | 86 | .SUFFIXES: .html .txt 87 | 88 | .c.o: 89 | $(CC) -c $(CFLAGS) $(CPPFLAGS) $(BUILD_CFLAGS) -o $@ $< 90 | 91 | .txt.html: 92 | $(ASCIIDOC) -n -a toc $< 93 | 94 | all: $(TARGET) 95 | 96 | doc: manual.html performance.html 97 | 98 | $(TARGET): $(OBJS) 99 | $(CC) $(LDFLAGS) $(CJSON_LDFLAGS) -o $@ $(OBJS) 100 | 101 | install: $(TARGET) 102 | mkdir -p $(DESTDIR)/$(LUA_CMODULE_DIR) 103 | cp $(TARGET) $(DESTDIR)/$(LUA_CMODULE_DIR) 104 | chmod $(EXECPERM) $(DESTDIR)/$(LUA_CMODULE_DIR)/$(TARGET) 105 | 106 | install-extra: 107 | mkdir -p $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/tests \ 108 | $(DESTDIR)/$(LUA_BIN_DIR) 109 | cp lua/cjson/util.lua $(DESTDIR)/$(LUA_MODULE_DIR)/cjson 110 | chmod $(DATAPERM) $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/util.lua 111 | cp lua/lua2json.lua $(DESTDIR)/$(LUA_BIN_DIR)/lua2json$(LUA_BIN_SUFFIX) 112 | chmod $(EXECPERM) $(DESTDIR)/$(LUA_BIN_DIR)/lua2json$(LUA_BIN_SUFFIX) 113 | cp lua/json2lua.lua $(DESTDIR)/$(LUA_BIN_DIR)/json2lua$(LUA_BIN_SUFFIX) 114 | chmod $(EXECPERM) $(DESTDIR)/$(LUA_BIN_DIR)/json2lua$(LUA_BIN_SUFFIX) 115 | cd tests; cp $(TEST_FILES) $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/tests 116 | cd tests; chmod $(DATAPERM) $(TEST_FILES); chmod $(EXECPERM) *.lua *.pl 117 | 118 | clean: 119 | rm -f *.o $(TARGET) 120 | -------------------------------------------------------------------------------- /src/matrix.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "matrix.h" 4 | #include "shader.h" 5 | 6 | namespace aroma { 7 | 8 | Mat4 Mat4::identity() { 9 | Mat4 out = { { 10 | 1, 0, 0, 0, 11 | 0, 1, 0, 0, 12 | 0, 0, 1, 0, 13 | 0, 0, 0, 1, 14 | } }; 15 | return out; 16 | } 17 | 18 | Mat4 Mat4::ortho2d(float left, float right, float top, float bottom) { 19 | float near = -1; 20 | float far = 1; 21 | 22 | float tx = - (right + left) / (right - left); 23 | float ty = - (top + bottom) / (top - bottom); 24 | float tz = - (far + near) / (far - near); 25 | 26 | Mat4 out = { 27 | 2.0/(right - left), 0, 0, 0, 28 | 0, 2.0/(top - bottom), 0, 0, 29 | 0, 0, -2.0/(far - near), 0, 30 | tx, ty, tz, 1, 31 | }; 32 | return out; 33 | } 34 | 35 | Mat4 Mat4::scale(float sx, float sy, float sz) { 36 | Mat4 out = { { 37 | sx, 0, 0, 0, 38 | 0, sy, 0, 0, 39 | 0, 0, sz, 0, 40 | 0, 0, 0, 1, 41 | } }; 42 | return out; 43 | } 44 | 45 | 46 | Mat4 Mat4::translate(float tx, float ty, float tz) { 47 | Mat4 out = { { 48 | 1, 0, 0, 0, 49 | 0, 1, 0, 0, 50 | 0, 0, 1, 0, 51 | tx, ty, tz, 1, 52 | } }; 53 | return out; 54 | } 55 | 56 | Mat4 Mat4::rotate2d(float theta) { 57 | Mat4 out = { { 58 | cos(theta), sin(theta), 0, 0, 59 | -sin(theta), cos(theta), 0, 0, 60 | 0, 0, 1, 0, 61 | 0, 0, 0, 1, 62 | } }; 63 | return out; 64 | } 65 | 66 | Mat4 Mat4::operator*(const Mat4 & other) const { 67 | // see lib/mult.moon 68 | Mat4 out = { { 69 | data[0] * other.data[0] + data[1] * other.data[4] + data[2] * other.data[8] + data[3] * other.data[12], 70 | data[0] * other.data[1] + data[1] * other.data[5] + data[2] * other.data[9] + data[3] * other.data[13], 71 | data[0] * other.data[2] + data[1] * other.data[6] + data[2] * other.data[10] + data[3] * other.data[14], 72 | data[0] * other.data[3] + data[1] * other.data[7] + data[2] * other.data[11] + data[3] * other.data[15], 73 | data[4] * other.data[0] + data[5] * other.data[4] + data[6] * other.data[8] + data[7] * other.data[12], 74 | data[4] * other.data[1] + data[5] * other.data[5] + data[6] * other.data[9] + data[7] * other.data[13], 75 | data[4] * other.data[2] + data[5] * other.data[6] + data[6] * other.data[10] + data[7] * other.data[14], 76 | data[4] * other.data[3] + data[5] * other.data[7] + data[6] * other.data[11] + data[7] * other.data[15], 77 | data[8] * other.data[0] + data[9] * other.data[4] + data[10] * other.data[8] + data[11] * other.data[12], 78 | data[8] * other.data[1] + data[9] * other.data[5] + data[10] * other.data[9] + data[11] * other.data[13], 79 | data[8] * other.data[2] + data[9] * other.data[6] + data[10] * other.data[10] + data[11] * other.data[14], 80 | data[8] * other.data[3] + data[9] * other.data[7] + data[10] * other.data[11] + data[11] * other.data[15], 81 | data[12] * other.data[0] + data[13] * other.data[4] + data[14] * other.data[8] + data[15] * other.data[12], 82 | data[12] * other.data[1] + data[13] * other.data[5] + data[14] * other.data[9] + data[15] * other.data[13], 83 | data[12] * other.data[2] + data[13] * other.data[6] + data[14] * other.data[10] + data[15] * other.data[14], 84 | data[12] * other.data[3] + data[13] * other.data[7] + data[14] * other.data[11] + data[15] * other.data[15] 85 | } }; 86 | return out; 87 | } 88 | 89 | void Mat4::print() { 90 | for (int i = 0; i < 16; i ++) { 91 | if ( i != 0 && i % 4 == 0) printf("\n"); 92 | 93 | printf("%f, ", data[i]); 94 | } 95 | printf("\n"); 96 | } 97 | 98 | MatrixStack::MatrixStack() { 99 | matrices.push(Mat4::identity()); 100 | } 101 | 102 | void MatrixStack::push(Mat4 mat) { 103 | matrices.push(mat * current()); 104 | } 105 | 106 | void MatrixStack::push() { 107 | matrices.push(current()); 108 | } 109 | 110 | void MatrixStack::set(Mat4 mat) { 111 | matrices.push(mat); 112 | } 113 | 114 | void MatrixStack::mul(Mat4 mat) { 115 | Mat4 top = mat * current(); 116 | if (matrices.size() == 1) { 117 | reset(top); 118 | } else { 119 | pop(); 120 | matrices.push(top); 121 | } 122 | } 123 | 124 | void MatrixStack::reset(Mat4 mat) { 125 | matrices = mstack(); 126 | matrices.push(mat); 127 | } 128 | 129 | void MatrixStack::pop() { 130 | if (matrices.size() == 1) { 131 | err("matrix stack underflow\n"); 132 | } else { 133 | matrices.pop(); 134 | } 135 | } 136 | 137 | Mat4 MatrixStack::current() { 138 | return matrices.top(); 139 | } 140 | 141 | void MatrixStack::apply(Shader *shader, const char* name) { 142 | shader->set_uniform(name, current()); 143 | } 144 | } 145 | 146 | -------------------------------------------------------------------------------- /site/js_reference.moon: -------------------------------------------------------------------------------- 1 | 2 | format "lib.reference" 3 | 4 | set "title", "JavaScript Reference" 5 | 6 | package { 7 | language: "javascript" 8 | name: "aroma.js" 9 | description: [[ 10 | The JavaScript API manages the creation and existence of your game in the 11 | browser. JavaScript is used to create the Aroma viewport and start the 12 | execution of your game. 13 | 14 | You can use this API to set up the size of your game viewport and handle 15 | any text sent to standard out or standard error. 16 | 17 | Create a game like so: 18 | 19 | ```html 20 | 21 |
22 | 23 | 31 | ``` 32 | 33 | The third argument of the `Aroma` constructor is an object of functions for 34 | various events. In this example we provide a function for the `loaded` 35 | event. The loaded event fires when Aroma's binary has finished downloading. 36 | 37 | After Aroma has loaded it will by default try to load `main`, which 38 | involves searching for `main.lua` in the current directory. 39 | 40 | In this example we overwrite the default load behavior and use the 41 | `execute` method to run arbitrary Lua in Aroma. 42 | 43 | ```javascript 44 | var game = new Aroma(container, 640, 480, { 45 | loaded: function() { 46 | game.execute("function aroma.draw() aroma.graphics.print('Hello World!', 10, 10) end"); 47 | } 48 | }); 49 | ``` 50 | 51 | The example above is one of the simplest examples of an Aroma game. 52 | 53 | By default, standard out is sent into Chrome's `console.log` and standard 54 | error is sent into `console.error`. This means if we use the Lua function 55 | `print` we will see the output in in the console. Likewise, if your code 56 | crashes the error information will also show up in the console. (You can 57 | open up the console by clicking on the wrench icon and going to Tools > 58 | JavaScript Console) 59 | ]] 60 | 61 | type { 62 | name: "Aroma" 63 | instance_name: "game" 64 | 65 | description: [[ 66 | Controls the game instance and message passing between the game and the 67 | browser. 68 | ]] 69 | 70 | constructor { 71 | args: {"container", "width", "height", "event_handlers"} 72 | returns: {"aroma"} 73 | description: [[ 74 | Creates Aroma frame and Lua environment. Causes the `nexe` to be 75 | downloaded if it hasn't been already. 76 | 77 | * `container` -- A DOM node where the game will be placed. Can also be a 78 | string which represents an id of a DOM node. 79 | 80 | * `width` -- Width of the frame in pixels. 81 | 82 | * `height` -- Height of the frame in pixels. 83 | 84 | * `event_handlers` -- An object containing functions for certain named 85 | events. 86 | 87 | 88 | Possible event handlers include: 89 | 90 | * `"loaded"` -- Called when the frame is ready to execute Lua. 91 | 92 | * `"std_out"` -- Called whenever Lua writes to standard out. Recieves one 93 | argument, what was written. 94 | 95 | * `"std_err"` -- Same as above, except for standard error. 96 | 97 | 98 | By default, `std_out` is set to write to `console.log` and `std_err` is 99 | set to write to `console.err`. 100 | 101 | The default loaded event executes the following Lua code: 102 | 103 | ```lua 104 | require "main" 105 | if aroma and aroma.load then 106 | aroma.load() 107 | end 108 | ``` 109 | ]] 110 | 111 | code: [[ 112 | var game = new Aroma("game_container", 640, 480, { 113 | loaded: function() { 114 | game.execute("print 'hello world!'"); 115 | }, 116 | std_out: function(msg) { 117 | alert(msg); 118 | } 119 | }); 120 | ]] 121 | } 122 | 123 | method { 124 | name: "execute" 125 | args: {"lua_code"} 126 | 127 | description: [[ 128 | Takes one argument, `lua_code`, a string of Lua code that will be 129 | executed. 130 | 131 | Will reset all game state. This should only be called when you want to 132 | run a new game. 133 | ]] 134 | } 135 | } 136 | 137 | } 138 | 139 | -------------------------------------------------------------------------------- /nacl/lua-cjson-2.1.0/strbuf.h: -------------------------------------------------------------------------------- 1 | /* strbuf - String buffer routines 2 | * 3 | * Copyright (c) 2010-2012 Mark Pulford 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | /* Size: Total bytes allocated to *buf 29 | * Length: String length, excluding optional NULL terminator. 30 | * Increment: Allocation increments when resizing the string buffer. 31 | * Dynamic: True if created via strbuf_new() 32 | */ 33 | 34 | typedef struct { 35 | char *buf; 36 | int size; 37 | int length; 38 | int increment; 39 | int dynamic; 40 | int reallocs; 41 | int debug; 42 | } strbuf_t; 43 | 44 | #ifndef STRBUF_DEFAULT_SIZE 45 | #define STRBUF_DEFAULT_SIZE 1023 46 | #endif 47 | #ifndef STRBUF_DEFAULT_INCREMENT 48 | #define STRBUF_DEFAULT_INCREMENT -2 49 | #endif 50 | 51 | /* Initialise */ 52 | extern strbuf_t *strbuf_new(int len); 53 | extern void strbuf_init(strbuf_t *s, int len); 54 | extern void strbuf_set_increment(strbuf_t *s, int increment); 55 | 56 | /* Release */ 57 | extern void strbuf_free(strbuf_t *s); 58 | extern char *strbuf_free_to_string(strbuf_t *s, int *len); 59 | 60 | /* Management */ 61 | extern void strbuf_resize(strbuf_t *s, int len); 62 | static int strbuf_empty_length(strbuf_t *s); 63 | static int strbuf_length(strbuf_t *s); 64 | static char *strbuf_string(strbuf_t *s, int *len); 65 | static void strbuf_ensure_empty_length(strbuf_t *s, int len); 66 | static char *strbuf_empty_ptr(strbuf_t *s); 67 | static void strbuf_extend_length(strbuf_t *s, int len); 68 | 69 | /* Update */ 70 | extern void strbuf_append_fmt(strbuf_t *s, int len, const char *fmt, ...); 71 | extern void strbuf_append_fmt_retry(strbuf_t *s, const char *format, ...); 72 | static void strbuf_append_mem(strbuf_t *s, const char *c, int len); 73 | extern void strbuf_append_string(strbuf_t *s, const char *str); 74 | static void strbuf_append_char(strbuf_t *s, const char c); 75 | static void strbuf_ensure_null(strbuf_t *s); 76 | 77 | /* Reset string for before use */ 78 | static inline void strbuf_reset(strbuf_t *s) 79 | { 80 | s->length = 0; 81 | } 82 | 83 | static inline int strbuf_allocated(strbuf_t *s) 84 | { 85 | return s->buf != NULL; 86 | } 87 | 88 | /* Return bytes remaining in the string buffer 89 | * Ensure there is space for a NULL terminator. */ 90 | static inline int strbuf_empty_length(strbuf_t *s) 91 | { 92 | return s->size - s->length - 1; 93 | } 94 | 95 | static inline void strbuf_ensure_empty_length(strbuf_t *s, int len) 96 | { 97 | if (len > strbuf_empty_length(s)) 98 | strbuf_resize(s, s->length + len); 99 | } 100 | 101 | static inline char *strbuf_empty_ptr(strbuf_t *s) 102 | { 103 | return s->buf + s->length; 104 | } 105 | 106 | static inline void strbuf_extend_length(strbuf_t *s, int len) 107 | { 108 | s->length += len; 109 | } 110 | 111 | static inline int strbuf_length(strbuf_t *s) 112 | { 113 | return s->length; 114 | } 115 | 116 | static inline void strbuf_append_char(strbuf_t *s, const char c) 117 | { 118 | strbuf_ensure_empty_length(s, 1); 119 | s->buf[s->length++] = c; 120 | } 121 | 122 | static inline void strbuf_append_char_unsafe(strbuf_t *s, const char c) 123 | { 124 | s->buf[s->length++] = c; 125 | } 126 | 127 | static inline void strbuf_append_mem(strbuf_t *s, const char *c, int len) 128 | { 129 | strbuf_ensure_empty_length(s, len); 130 | memcpy(s->buf + s->length, c, len); 131 | s->length += len; 132 | } 133 | 134 | static inline void strbuf_append_mem_unsafe(strbuf_t *s, const char *c, int len) 135 | { 136 | memcpy(s->buf + s->length, c, len); 137 | s->length += len; 138 | } 139 | 140 | static inline void strbuf_ensure_null(strbuf_t *s) 141 | { 142 | s->buf[s->length] = 0; 143 | } 144 | 145 | static inline char *strbuf_string(strbuf_t *s, int *len) 146 | { 147 | if (len) 148 | *len = s->length; 149 | 150 | return s->buf; 151 | } 152 | 153 | /* vi:ai et sw=4 ts=4: 154 | */ 155 | -------------------------------------------------------------------------------- /nacl/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | hi 6 | 62 | 63 | 64 |
65 | 66 |
67 | 68 |
69 | 70 | 71 | Loading... 72 | 73 | 74 |
75 |
76 | 77 |
78 |
    79 |
80 |
81 | 82 |

 83 | 
 84 |   
 85 |   
192 | 
193 | 
194 | 


--------------------------------------------------------------------------------
/nacl/lua-5.1.5/src/lfunc.c:
--------------------------------------------------------------------------------
  1 | /*
  2 | ** $Id: lfunc.c,v 2.12.1.2 2007/12/28 14:58:43 roberto Exp $
  3 | ** Auxiliary functions to manipulate prototypes and closures
  4 | ** See Copyright Notice in lua.h
  5 | */
  6 | 
  7 | 
  8 | #include 
  9 | 
 10 | #define lfunc_c
 11 | #define LUA_CORE
 12 | 
 13 | #include "lua.h"
 14 | 
 15 | #include "lfunc.h"
 16 | #include "lgc.h"
 17 | #include "lmem.h"
 18 | #include "lobject.h"
 19 | #include "lstate.h"
 20 | 
 21 | 
 22 | 
 23 | Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) {
 24 |   Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));
 25 |   luaC_link(L, obj2gco(c), LUA_TFUNCTION);
 26 |   c->c.isC = 1;
 27 |   c->c.env = e;
 28 |   c->c.nupvalues = cast_byte(nelems);
 29 |   return c;
 30 | }
 31 | 
 32 | 
 33 | Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) {
 34 |   Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));
 35 |   luaC_link(L, obj2gco(c), LUA_TFUNCTION);
 36 |   c->l.isC = 0;
 37 |   c->l.env = e;
 38 |   c->l.nupvalues = cast_byte(nelems);
 39 |   while (nelems--) c->l.upvals[nelems] = NULL;
 40 |   return c;
 41 | }
 42 | 
 43 | 
 44 | UpVal *luaF_newupval (lua_State *L) {
 45 |   UpVal *uv = luaM_new(L, UpVal);
 46 |   luaC_link(L, obj2gco(uv), LUA_TUPVAL);
 47 |   uv->v = &uv->u.value;
 48 |   setnilvalue(uv->v);
 49 |   return uv;
 50 | }
 51 | 
 52 | 
 53 | UpVal *luaF_findupval (lua_State *L, StkId level) {
 54 |   global_State *g = G(L);
 55 |   GCObject **pp = &L->openupval;
 56 |   UpVal *p;
 57 |   UpVal *uv;
 58 |   while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) {
 59 |     lua_assert(p->v != &p->u.value);
 60 |     if (p->v == level) {  /* found a corresponding upvalue? */
 61 |       if (isdead(g, obj2gco(p)))  /* is it dead? */
 62 |         changewhite(obj2gco(p));  /* ressurect it */
 63 |       return p;
 64 |     }
 65 |     pp = &p->next;
 66 |   }
 67 |   uv = luaM_new(L, UpVal);  /* not found: create a new one */
 68 |   uv->tt = LUA_TUPVAL;
 69 |   uv->marked = luaC_white(g);
 70 |   uv->v = level;  /* current value lives in the stack */
 71 |   uv->next = *pp;  /* chain it in the proper position */
 72 |   *pp = obj2gco(uv);
 73 |   uv->u.l.prev = &g->uvhead;  /* double link it in `uvhead' list */
 74 |   uv->u.l.next = g->uvhead.u.l.next;
 75 |   uv->u.l.next->u.l.prev = uv;
 76 |   g->uvhead.u.l.next = uv;
 77 |   lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
 78 |   return uv;
 79 | }
 80 | 
 81 | 
 82 | static void unlinkupval (UpVal *uv) {
 83 |   lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
 84 |   uv->u.l.next->u.l.prev = uv->u.l.prev;  /* remove from `uvhead' list */
 85 |   uv->u.l.prev->u.l.next = uv->u.l.next;
 86 | }
 87 | 
 88 | 
 89 | void luaF_freeupval (lua_State *L, UpVal *uv) {
 90 |   if (uv->v != &uv->u.value)  /* is it open? */
 91 |     unlinkupval(uv);  /* remove from open list */
 92 |   luaM_free(L, uv);  /* free upvalue */
 93 | }
 94 | 
 95 | 
 96 | void luaF_close (lua_State *L, StkId level) {
 97 |   UpVal *uv;
 98 |   global_State *g = G(L);
 99 |   while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) {
100 |     GCObject *o = obj2gco(uv);
101 |     lua_assert(!isblack(o) && uv->v != &uv->u.value);
102 |     L->openupval = uv->next;  /* remove from `open' list */
103 |     if (isdead(g, o))
104 |       luaF_freeupval(L, uv);  /* free upvalue */
105 |     else {
106 |       unlinkupval(uv);
107 |       setobj(L, &uv->u.value, uv->v);
108 |       uv->v = &uv->u.value;  /* now current value lives here */
109 |       luaC_linkupval(L, uv);  /* link upvalue into `gcroot' list */
110 |     }
111 |   }
112 | }
113 | 
114 | 
115 | Proto *luaF_newproto (lua_State *L) {
116 |   Proto *f = luaM_new(L, Proto);
117 |   luaC_link(L, obj2gco(f), LUA_TPROTO);
118 |   f->k = NULL;
119 |   f->sizek = 0;
120 |   f->p = NULL;
121 |   f->sizep = 0;
122 |   f->code = NULL;
123 |   f->sizecode = 0;
124 |   f->sizelineinfo = 0;
125 |   f->sizeupvalues = 0;
126 |   f->nups = 0;
127 |   f->upvalues = NULL;
128 |   f->numparams = 0;
129 |   f->is_vararg = 0;
130 |   f->maxstacksize = 0;
131 |   f->lineinfo = NULL;
132 |   f->sizelocvars = 0;
133 |   f->locvars = NULL;
134 |   f->linedefined = 0;
135 |   f->lastlinedefined = 0;
136 |   f->source = NULL;
137 |   return f;
138 | }
139 | 
140 | 
141 | void luaF_freeproto (lua_State *L, Proto *f) {
142 |   luaM_freearray(L, f->code, f->sizecode, Instruction);
143 |   luaM_freearray(L, f->p, f->sizep, Proto *);
144 |   luaM_freearray(L, f->k, f->sizek, TValue);
145 |   luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
146 |   luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
147 |   luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
148 |   luaM_free(L, f);
149 | }
150 | 
151 | 
152 | void luaF_freeclosure (lua_State *L, Closure *c) {
153 |   int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
154 |                           sizeLclosure(c->l.nupvalues);
155 |   luaM_freemem(L, c, size);
156 | }
157 | 
158 | 
159 | /*
160 | ** Look for n-th local variable at line `line' in function `func'.
161 | ** Returns NULL if not found.
162 | */
163 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) {
164 |   int i;
165 |   for (i = 0; isizelocvars && f->locvars[i].startpc <= pc; i++) {
166 |     if (pc < f->locvars[i].endpc) {  /* is variable active? */
167 |       local_number--;
168 |       if (local_number == 0)
169 |         return getstr(f->locvars[i].varname);
170 |     }
171 |   }
172 |   return NULL;  /* not found */
173 | }
174 | 
175 | 


--------------------------------------------------------------------------------
/nacl/lua-5.1.5/src/luac.c:
--------------------------------------------------------------------------------
  1 | /*
  2 | ** $Id: luac.c,v 1.54 2006/06/02 17:37:11 lhf Exp $
  3 | ** Lua compiler (saves bytecodes to files; also list bytecodes)
  4 | ** See Copyright Notice in lua.h
  5 | */
  6 | 
  7 | #include 
  8 | #include 
  9 | #include 
 10 | #include 
 11 | 
 12 | #define luac_c
 13 | #define LUA_CORE
 14 | 
 15 | #include "lua.h"
 16 | #include "lauxlib.h"
 17 | 
 18 | #include "ldo.h"
 19 | #include "lfunc.h"
 20 | #include "lmem.h"
 21 | #include "lobject.h"
 22 | #include "lopcodes.h"
 23 | #include "lstring.h"
 24 | #include "lundump.h"
 25 | 
 26 | #define PROGNAME	"luac"		/* default program name */
 27 | #define	OUTPUT		PROGNAME ".out"	/* default output file */
 28 | 
 29 | static int listing=0;			/* list bytecodes? */
 30 | static int dumping=1;			/* dump bytecodes? */
 31 | static int stripping=0;			/* strip debug information? */
 32 | static char Output[]={ OUTPUT };	/* default output file name */
 33 | static const char* output=Output;	/* actual output file name */
 34 | static const char* progname=PROGNAME;	/* actual program name */
 35 | 
 36 | static void fatal(const char* message)
 37 | {
 38 |  fprintf(stderr,"%s: %s\n",progname,message);
 39 |  exit(EXIT_FAILURE);
 40 | }
 41 | 
 42 | static void cannot(const char* what)
 43 | {
 44 |  fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno));
 45 |  exit(EXIT_FAILURE);
 46 | }
 47 | 
 48 | static void usage(const char* message)
 49 | {
 50 |  if (*message=='-')
 51 |   fprintf(stderr,"%s: unrecognized option " LUA_QS "\n",progname,message);
 52 |  else
 53 |   fprintf(stderr,"%s: %s\n",progname,message);
 54 |  fprintf(stderr,
 55 |  "usage: %s [options] [filenames].\n"
 56 |  "Available options are:\n"
 57 |  "  -        process stdin\n"
 58 |  "  -l       list\n"
 59 |  "  -o name  output to file " LUA_QL("name") " (default is \"%s\")\n"
 60 |  "  -p       parse only\n"
 61 |  "  -s       strip debug information\n"
 62 |  "  -v       show version information\n"
 63 |  "  --       stop handling options\n",
 64 |  progname,Output);
 65 |  exit(EXIT_FAILURE);
 66 | }
 67 | 
 68 | #define	IS(s)	(strcmp(argv[i],s)==0)
 69 | 
 70 | static int doargs(int argc, char* argv[])
 71 | {
 72 |  int i;
 73 |  int version=0;
 74 |  if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0];
 75 |  for (i=1; itop+(i))->l.p)
118 | 
119 | static const Proto* combine(lua_State* L, int n)
120 | {
121 |  if (n==1)
122 |   return toproto(L,-1);
123 |  else
124 |  {
125 |   int i,pc;
126 |   Proto* f=luaF_newproto(L);
127 |   setptvalue2s(L,L->top,f); incr_top(L);
128 |   f->source=luaS_newliteral(L,"=(" PROGNAME ")");
129 |   f->maxstacksize=1;
130 |   pc=2*n+1;
131 |   f->code=luaM_newvector(L,pc,Instruction);
132 |   f->sizecode=pc;
133 |   f->p=luaM_newvector(L,n,Proto*);
134 |   f->sizep=n;
135 |   pc=0;
136 |   for (i=0; ip[i]=toproto(L,i-n-1);
139 |    f->code[pc++]=CREATE_ABx(OP_CLOSURE,0,i);
140 |    f->code[pc++]=CREATE_ABC(OP_CALL,0,1,1);
141 |   }
142 |   f->code[pc++]=CREATE_ABC(OP_RETURN,0,1,0);
143 |   return f;
144 |  }
145 | }
146 | 
147 | static int writer(lua_State* L, const void* p, size_t size, void* u)
148 | {
149 |  UNUSED(L);
150 |  return (fwrite(p,size,1,(FILE*)u)!=1) && (size!=0);
151 | }
152 | 
153 | struct Smain {
154 |  int argc;
155 |  char** argv;
156 | };
157 | 
158 | static int pmain(lua_State* L)
159 | {
160 |  struct Smain* s = (struct Smain*)lua_touserdata(L, 1);
161 |  int argc=s->argc;
162 |  char** argv=s->argv;
163 |  const Proto* f;
164 |  int i;
165 |  if (!lua_checkstack(L,argc)) fatal("too many input files");
166 |  for (i=0; i1);
173 |  if (dumping)
174 |  {
175 |   FILE* D= (output==NULL) ? stdout : fopen(output,"wb");
176 |   if (D==NULL) cannot("open");
177 |   lua_lock(L);
178 |   luaU_dump(L,f,writer,D,stripping);
179 |   lua_unlock(L);
180 |   if (ferror(D)) cannot("write");
181 |   if (fclose(D)) cannot("close");
182 |  }
183 |  return 0;
184 | }
185 | 
186 | int main(int argc, char* argv[])
187 | {
188 |  lua_State* L;
189 |  struct Smain s;
190 |  int i=doargs(argc,argv);
191 |  argc-=i; argv+=i;
192 |  if (argc<=0) usage("no input files given");
193 |  L=lua_open();
194 |  if (L==NULL) fatal("not enough memory for state");
195 |  s.argc=argc;
196 |  s.argv=argv;
197 |  if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));
198 |  lua_close(L);
199 |  return EXIT_SUCCESS;
200 | }
201 | 


--------------------------------------------------------------------------------
/nacl/lua-5.1.5/src/lundump.c:
--------------------------------------------------------------------------------
  1 | /*
  2 | ** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $
  3 | ** load precompiled Lua chunks
  4 | ** See Copyright Notice in lua.h
  5 | */
  6 | 
  7 | #include 
  8 | 
  9 | #define lundump_c
 10 | #define LUA_CORE
 11 | 
 12 | #include "lua.h"
 13 | 
 14 | #include "ldebug.h"
 15 | #include "ldo.h"
 16 | #include "lfunc.h"
 17 | #include "lmem.h"
 18 | #include "lobject.h"
 19 | #include "lstring.h"
 20 | #include "lundump.h"
 21 | #include "lzio.h"
 22 | 
 23 | typedef struct {
 24 |  lua_State* L;
 25 |  ZIO* Z;
 26 |  Mbuffer* b;
 27 |  const char* name;
 28 | } LoadState;
 29 | 
 30 | #ifdef LUAC_TRUST_BINARIES
 31 | #define IF(c,s)
 32 | #define error(S,s)
 33 | #else
 34 | #define IF(c,s)		if (c) error(S,s)
 35 | 
 36 | static void error(LoadState* S, const char* why)
 37 | {
 38 |  luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why);
 39 |  luaD_throw(S->L,LUA_ERRSYNTAX);
 40 | }
 41 | #endif
 42 | 
 43 | #define LoadMem(S,b,n,size)	LoadBlock(S,b,(n)*(size))
 44 | #define	LoadByte(S)		(lu_byte)LoadChar(S)
 45 | #define LoadVar(S,x)		LoadMem(S,&x,1,sizeof(x))
 46 | #define LoadVector(S,b,n,size)	LoadMem(S,b,n,size)
 47 | 
 48 | static void LoadBlock(LoadState* S, void* b, size_t size)
 49 | {
 50 |  size_t r=luaZ_read(S->Z,b,size);
 51 |  IF (r!=0, "unexpected end");
 52 | }
 53 | 
 54 | static int LoadChar(LoadState* S)
 55 | {
 56 |  char x;
 57 |  LoadVar(S,x);
 58 |  return x;
 59 | }
 60 | 
 61 | static int LoadInt(LoadState* S)
 62 | {
 63 |  int x;
 64 |  LoadVar(S,x);
 65 |  IF (x<0, "bad integer");
 66 |  return x;
 67 | }
 68 | 
 69 | static lua_Number LoadNumber(LoadState* S)
 70 | {
 71 |  lua_Number x;
 72 |  LoadVar(S,x);
 73 |  return x;
 74 | }
 75 | 
 76 | static TString* LoadString(LoadState* S)
 77 | {
 78 |  size_t size;
 79 |  LoadVar(S,size);
 80 |  if (size==0)
 81 |   return NULL;
 82 |  else
 83 |  {
 84 |   char* s=luaZ_openspace(S->L,S->b,size);
 85 |   LoadBlock(S,s,size);
 86 |   return luaS_newlstr(S->L,s,size-1);		/* remove trailing '\0' */
 87 |  }
 88 | }
 89 | 
 90 | static void LoadCode(LoadState* S, Proto* f)
 91 | {
 92 |  int n=LoadInt(S);
 93 |  f->code=luaM_newvector(S->L,n,Instruction);
 94 |  f->sizecode=n;
 95 |  LoadVector(S,f->code,n,sizeof(Instruction));
 96 | }
 97 | 
 98 | static Proto* LoadFunction(LoadState* S, TString* p);
 99 | 
100 | static void LoadConstants(LoadState* S, Proto* f)
101 | {
102 |  int i,n;
103 |  n=LoadInt(S);
104 |  f->k=luaM_newvector(S->L,n,TValue);
105 |  f->sizek=n;
106 |  for (i=0; ik[i]);
107 |  for (i=0; ik[i];
110 |   int t=LoadChar(S);
111 |   switch (t)
112 |   {
113 |    case LUA_TNIL:
114 |    	setnilvalue(o);
115 | 	break;
116 |    case LUA_TBOOLEAN:
117 |    	setbvalue(o,LoadChar(S)!=0);
118 | 	break;
119 |    case LUA_TNUMBER:
120 | 	setnvalue(o,LoadNumber(S));
121 | 	break;
122 |    case LUA_TSTRING:
123 | 	setsvalue2n(S->L,o,LoadString(S));
124 | 	break;
125 |    default:
126 | 	error(S,"bad constant");
127 | 	break;
128 |   }
129 |  }
130 |  n=LoadInt(S);
131 |  f->p=luaM_newvector(S->L,n,Proto*);
132 |  f->sizep=n;
133 |  for (i=0; ip[i]=NULL;
134 |  for (i=0; ip[i]=LoadFunction(S,f->source);
135 | }
136 | 
137 | static void LoadDebug(LoadState* S, Proto* f)
138 | {
139 |  int i,n;
140 |  n=LoadInt(S);
141 |  f->lineinfo=luaM_newvector(S->L,n,int);
142 |  f->sizelineinfo=n;
143 |  LoadVector(S,f->lineinfo,n,sizeof(int));
144 |  n=LoadInt(S);
145 |  f->locvars=luaM_newvector(S->L,n,LocVar);
146 |  f->sizelocvars=n;
147 |  for (i=0; ilocvars[i].varname=NULL;
148 |  for (i=0; ilocvars[i].varname=LoadString(S);
151 |   f->locvars[i].startpc=LoadInt(S);
152 |   f->locvars[i].endpc=LoadInt(S);
153 |  }
154 |  n=LoadInt(S);
155 |  f->upvalues=luaM_newvector(S->L,n,TString*);
156 |  f->sizeupvalues=n;
157 |  for (i=0; iupvalues[i]=NULL;
158 |  for (i=0; iupvalues[i]=LoadString(S);
159 | }
160 | 
161 | static Proto* LoadFunction(LoadState* S, TString* p)
162 | {
163 |  Proto* f;
164 |  if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
165 |  f=luaF_newproto(S->L);
166 |  setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
167 |  f->source=LoadString(S); if (f->source==NULL) f->source=p;
168 |  f->linedefined=LoadInt(S);
169 |  f->lastlinedefined=LoadInt(S);
170 |  f->nups=LoadByte(S);
171 |  f->numparams=LoadByte(S);
172 |  f->is_vararg=LoadByte(S);
173 |  f->maxstacksize=LoadByte(S);
174 |  LoadCode(S,f);
175 |  LoadConstants(S,f);
176 |  LoadDebug(S,f);
177 |  IF (!luaG_checkcode(f), "bad code");
178 |  S->L->top--;
179 |  S->L->nCcalls--;
180 |  return f;
181 | }
182 | 
183 | static void LoadHeader(LoadState* S)
184 | {
185 |  char h[LUAC_HEADERSIZE];
186 |  char s[LUAC_HEADERSIZE];
187 |  luaU_header(h);
188 |  LoadBlock(S,s,LUAC_HEADERSIZE);
189 |  IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
190 | }
191 | 
192 | /*
193 | ** load precompiled chunk
194 | */
195 | Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
196 | {
197 |  LoadState S;
198 |  if (*name=='@' || *name=='=')
199 |   S.name=name+1;
200 |  else if (*name==LUA_SIGNATURE[0])
201 |   S.name="binary string";
202 |  else
203 |   S.name=name;
204 |  S.L=L;
205 |  S.Z=Z;
206 |  S.b=buff;
207 |  LoadHeader(&S);
208 |  return LoadFunction(&S,luaS_newliteral(L,"=?"));
209 | }
210 | 
211 | /*
212 | * make header
213 | */
214 | void luaU_header (char* h)
215 | {
216 |  int x=1;
217 |  memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
218 |  h+=sizeof(LUA_SIGNATURE)-1;
219 |  *h++=(char)LUAC_VERSION;
220 |  *h++=(char)LUAC_FORMAT;
221 |  *h++=(char)*(char*)&x;				/* endianness */
222 |  *h++=(char)sizeof(int);
223 |  *h++=(char)sizeof(size_t);
224 |  *h++=(char)sizeof(Instruction);
225 |  *h++=(char)sizeof(lua_Number);
226 |  *h++=(char)(((lua_Number)0.5)==0);		/* is lua_Number integral? */
227 | }
228 | 


--------------------------------------------------------------------------------
/nacl/lua-5.1.5/src/lstate.h:
--------------------------------------------------------------------------------
  1 | /*
  2 | ** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
  3 | ** Global State
  4 | ** See Copyright Notice in lua.h
  5 | */
  6 | 
  7 | #ifndef lstate_h
  8 | #define lstate_h
  9 | 
 10 | #include "lua.h"
 11 | 
 12 | #include "lobject.h"
 13 | #include "ltm.h"
 14 | #include "lzio.h"
 15 | 
 16 | 
 17 | 
 18 | struct lua_longjmp;  /* defined in ldo.c */
 19 | 
 20 | 
 21 | /* table of globals */
 22 | #define gt(L)	(&L->l_gt)
 23 | 
 24 | /* registry */
 25 | #define registry(L)	(&G(L)->l_registry)
 26 | 
 27 | 
 28 | /* extra stack space to handle TM calls and some other extras */
 29 | #define EXTRA_STACK   5
 30 | 
 31 | 
 32 | #define BASIC_CI_SIZE           8
 33 | 
 34 | #define BASIC_STACK_SIZE        (2*LUA_MINSTACK)
 35 | 
 36 | 
 37 | 
 38 | typedef struct stringtable {
 39 |   GCObject **hash;
 40 |   lu_int32 nuse;  /* number of elements */
 41 |   int size;
 42 | } stringtable;
 43 | 
 44 | 
 45 | /*
 46 | ** informations about a call
 47 | */
 48 | typedef struct CallInfo {
 49 |   StkId base;  /* base for this function */
 50 |   StkId func;  /* function index in the stack */
 51 |   StkId	top;  /* top for this function */
 52 |   const Instruction *savedpc;
 53 |   int nresults;  /* expected number of results from this function */
 54 |   int tailcalls;  /* number of tail calls lost under this entry */
 55 | } CallInfo;
 56 | 
 57 | 
 58 | 
 59 | #define curr_func(L)	(clvalue(L->ci->func))
 60 | #define ci_func(ci)	(clvalue((ci)->func))
 61 | #define f_isLua(ci)	(!ci_func(ci)->c.isC)
 62 | #define isLua(ci)	(ttisfunction((ci)->func) && f_isLua(ci))
 63 | 
 64 | 
 65 | /*
 66 | ** `global state', shared by all threads of this state
 67 | */
 68 | typedef struct global_State {
 69 |   stringtable strt;  /* hash table for strings */
 70 |   lua_Alloc frealloc;  /* function to reallocate memory */
 71 |   void *ud;         /* auxiliary data to `frealloc' */
 72 |   lu_byte currentwhite;
 73 |   lu_byte gcstate;  /* state of garbage collector */
 74 |   int sweepstrgc;  /* position of sweep in `strt' */
 75 |   GCObject *rootgc;  /* list of all collectable objects */
 76 |   GCObject **sweepgc;  /* position of sweep in `rootgc' */
 77 |   GCObject *gray;  /* list of gray objects */
 78 |   GCObject *grayagain;  /* list of objects to be traversed atomically */
 79 |   GCObject *weak;  /* list of weak tables (to be cleared) */
 80 |   GCObject *tmudata;  /* last element of list of userdata to be GC */
 81 |   Mbuffer buff;  /* temporary buffer for string concatentation */
 82 |   lu_mem GCthreshold;
 83 |   lu_mem totalbytes;  /* number of bytes currently allocated */
 84 |   lu_mem estimate;  /* an estimate of number of bytes actually in use */
 85 |   lu_mem gcdept;  /* how much GC is `behind schedule' */
 86 |   int gcpause;  /* size of pause between successive GCs */
 87 |   int gcstepmul;  /* GC `granularity' */
 88 |   lua_CFunction panic;  /* to be called in unprotected errors */
 89 |   TValue l_registry;
 90 |   struct lua_State *mainthread;
 91 |   UpVal uvhead;  /* head of double-linked list of all open upvalues */
 92 |   struct Table *mt[NUM_TAGS];  /* metatables for basic types */
 93 |   TString *tmname[TM_N];  /* array with tag-method names */
 94 | } global_State;
 95 | 
 96 | 
 97 | /*
 98 | ** `per thread' state
 99 | */
100 | struct lua_State {
101 |   CommonHeader;
102 |   lu_byte status;
103 |   StkId top;  /* first free slot in the stack */
104 |   StkId base;  /* base of current function */
105 |   global_State *l_G;
106 |   CallInfo *ci;  /* call info for current function */
107 |   const Instruction *savedpc;  /* `savedpc' of current function */
108 |   StkId stack_last;  /* last free slot in the stack */
109 |   StkId stack;  /* stack base */
110 |   CallInfo *end_ci;  /* points after end of ci array*/
111 |   CallInfo *base_ci;  /* array of CallInfo's */
112 |   int stacksize;
113 |   int size_ci;  /* size of array `base_ci' */
114 |   unsigned short nCcalls;  /* number of nested C calls */
115 |   unsigned short baseCcalls;  /* nested C calls when resuming coroutine */
116 |   lu_byte hookmask;
117 |   lu_byte allowhook;
118 |   int basehookcount;
119 |   int hookcount;
120 |   lua_Hook hook;
121 |   TValue l_gt;  /* table of globals */
122 |   TValue env;  /* temporary place for environments */
123 |   GCObject *openupval;  /* list of open upvalues in this stack */
124 |   GCObject *gclist;
125 |   struct lua_longjmp *errorJmp;  /* current error recover point */
126 |   ptrdiff_t errfunc;  /* current error handling function (stack index) */
127 | };
128 | 
129 | 
130 | #define G(L)	(L->l_G)
131 | 
132 | 
133 | /*
134 | ** Union of all collectable objects
135 | */
136 | union GCObject {
137 |   GCheader gch;
138 |   union TString ts;
139 |   union Udata u;
140 |   union Closure cl;
141 |   struct Table h;
142 |   struct Proto p;
143 |   struct UpVal uv;
144 |   struct lua_State th;  /* thread */
145 | };
146 | 
147 | 
148 | /* macros to convert a GCObject into a specific value */
149 | #define rawgco2ts(o)	check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
150 | #define gco2ts(o)	(&rawgco2ts(o)->tsv)
151 | #define rawgco2u(o)	check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
152 | #define gco2u(o)	(&rawgco2u(o)->uv)
153 | #define gco2cl(o)	check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
154 | #define gco2h(o)	check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
155 | #define gco2p(o)	check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
156 | #define gco2uv(o)	check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
157 | #define ngcotouv(o) \
158 | 	check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
159 | #define gco2th(o)	check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
160 | 
161 | /* macro to convert any Lua object into a GCObject */
162 | #define obj2gco(v)	(cast(GCObject *, (v)))
163 | 
164 | 
165 | LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
166 | LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
167 | 
168 | #endif
169 | 
170 | 


--------------------------------------------------------------------------------
/src/shader.cpp:
--------------------------------------------------------------------------------
  1 | 
  2 | #include "shader.h"
  3 | #include "image.h"
  4 | 
  5 | namespace aroma {
  6 | 
  7 | void register_Shader(lua_State *l) {
  8 | 	setfunction("shader", Shader::_new);
  9 | }
 10 | 
 11 | void dumpShaderLog(GLuint shader) {
 12 | 	int len;
 13 | 	glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len);
 14 | 	if (len > 1) {
 15 | 		int written;
 16 | 		char log[len];
 17 | 		glGetShaderInfoLog(shader, len, &written, log);
 18 | 		fprintf(stderr, "%s\n", log);
 19 | 	}
 20 | }
 21 | 
 22 | void dumpProgramLog(GLuint program) {
 23 | 	int len;
 24 | 	glGetProgramiv(program, GL_INFO_LOG_LENGTH, &len);
 25 | 	if (len > 1) {
 26 | 		int written;
 27 | 		char log[len];
 28 | 		glGetProgramInfoLog(program, len, &written, log);
 29 | 		fprintf(stderr, "%s\n", log);
 30 | 	}
 31 | }
 32 | 
 33 | Shader::Shader() : linked(false) {
 34 | 	program = glCreateProgram();
 35 | }
 36 | 
 37 | // create a new shader
 38 | // aroma.graphics.newShader([vertex_src], frag_src);
 39 | int Shader::_new(lua_State *l) {
 40 | 	int argc = lua_gettop(l);
 41 | 
 42 | 	Shader s;
 43 | 	bool success = true;
 44 | 	if (argc > 0) {
 45 | 		log("compiling fragment shader\n");
 46 | 		const char *frag = luaL_checkstring(l, -1);
 47 | 		success &= s.add(GL_FRAGMENT_SHADER, frag);
 48 | 	}
 49 | 
 50 | 	if (argc > 1) {
 51 | 		log("compiling vertex shader\n");
 52 | 		const char *vert = luaL_checkstring(l, -2);
 53 | 		success &= s.add(GL_VERTEX_SHADER, vert);
 54 | 	}
 55 | 
 56 | 	if (!success)
 57 | 		return luaL_error(l, "Shader: failed to compile");
 58 | 
 59 | 	*newuserdata(Shader) = s;
 60 | 
 61 | 	if (luaL_newmetatable(l, "Shader")) {
 62 | 		lua_newtable(l);		
 63 | 
 64 | 		setfunction("bind", Shader::_bind);
 65 | 		setfunction("release", Shader::_release);
 66 | 		setfunction("uniform", Shader::_uniform);
 67 | 		setfunction("vert", Shader::_vert);
 68 | 		setfunction("frag", Shader::_frag);
 69 | 
 70 | 		lua_setfield(l, -2, "__index");
 71 | 
 72 | 		setfunction("__gc", Shader::_gc);
 73 | 	}
 74 | 	lua_setmetatable(l, -2);
 75 | 
 76 | 	return 1;
 77 | }
 78 | 
 79 | 
 80 | int Shader::_gc(lua_State *l) {
 81 | 	Shader *self = getself(Shader);
 82 | 	glDeleteProgram(self->program);
 83 | 	self->program = -1;
 84 | 	return 0;
 85 | }
 86 | 
 87 | 
 88 | int Shader::_frag(lua_State *l) {
 89 | 	Shader *self = getself(Shader);
 90 | 	const char *src = luaL_checkstring(l, -1);
 91 | 	if (!self->add(GL_FRAGMENT_SHADER, src)) {
 92 | 		return luaL_error(l, "Shader: failed to compile fragment shader");
 93 | 	}
 94 | 
 95 | 	return 0;
 96 | }
 97 | 
 98 | int Shader::_vert(lua_State *l) {
 99 | 	Shader *self = getself(Shader);
100 | 	const char *src = luaL_checkstring(l, -1);
101 | 	if (!self->add(GL_VERTEX_SHADER, src)) {
102 | 		return luaL_error(l, "Shader: failed to compile fragment shader");
103 | 	}
104 | 	return 0;
105 | }
106 | 
107 | 
108 | int Shader::_bind(lua_State *l) {
109 | 	Shader *self = getself(Shader);
110 | 	if (!self->linked && !self->link()) {
111 | 		luaL_error(l, "Shader: failed to link shader");
112 | 	}
113 | 
114 | 	self->bind();
115 | 
116 | 
117 | 	if (LUA_TTABLE == lua_type(l, -1)) {
118 | 		return _uniform(l);
119 | 	}
120 | 
121 | 	return 0;
122 | }
123 | 
124 | int Shader::_release(lua_State *l) {
125 | 	glUseProgram(0);
126 | 	return 0;
127 | }
128 | 
129 | /**
130 |  * set some uniform values
131 |  */
132 | int Shader::_uniform(lua_State *l) {
133 | 	Shader *self = getself(Shader);
134 | 	lua_pushnil(l);
135 | 	while (lua_next(l, -2) != 0) {
136 | 		const char *key = luaL_checkstring(l, -2);
137 | 		GLuint uloc = self->uniform_loc(key);
138 | 
139 | 		int type = lua_type(l, -1);
140 | 		switch (type) {
141 | 			case LUA_TNUMBER:
142 | 				glUniform1f(uloc, luaL_checknumber(l, -1));
143 | 				break;
144 | 			case LUA_TUSERDATA: {
145 | 				// this is wrong: it is based on texture unit
146 | 				Image *image = (Image*)luaL_checkudata(l, -1, "Image");
147 | 				if (image) {
148 | 					glUniform1i(uloc, image->texid);
149 | 				}
150 | 				break;
151 | 			}
152 | 			default:
153 | 				log("unknown uniform type: %d\n", type);
154 | 		}
155 | 
156 | 		lua_pop(l, 1);
157 | 	}
158 | 
159 | 	return 0;
160 | }
161 | 
162 | bool Shader::add(GLuint type, const char *src) {
163 | 	if (linked) return false;
164 | 	GLuint sid = glCreateShader(type);
165 | 	glShaderSource(sid, 1, &src, NULL);
166 | 
167 | 	glCompileShader(sid);
168 | 	dumpShaderLog(sid);
169 | 
170 | 	int compiled;
171 | 	glGetShaderiv(sid, GL_COMPILE_STATUS, &compiled);
172 | 	if (!compiled) return false;
173 | 
174 | 	glAttachShader(program, sid);
175 | 
176 | 	return true;
177 | }
178 | 
179 | bool Shader::link() {
180 | 	if (linked) return true;
181 | 
182 | 	glLinkProgram(program);
183 | 	int success;
184 | 	glGetProgramiv(program, GL_LINK_STATUS, &success);
185 | 	if (!success) {
186 | 		dumpProgramLog(program);
187 | 		return false;
188 | 	}
189 | 
190 | 	linked = true;
191 | 	return true;
192 | }
193 | 
194 | void Shader::bind() {
195 | 	glUseProgram(program);
196 | }
197 | 
198 | GLuint Shader::attr_loc(const char* name) {
199 | 	return glGetAttribLocation(program, name);
200 | }
201 | 
202 | GLuint Shader::uniform_loc(const char* name) {
203 | 	return glGetUniformLocation(program, name);
204 | }
205 | 
206 | void Shader::set_uniform(const char* name, const Mat4 & matrix) {
207 | 	GLuint loc = glGetUniformLocation(program, name);
208 | 	glUniformMatrix4fv(loc, 1, GL_FALSE, (const GLfloat*)&matrix);
209 | }
210 | 
211 | void Shader::set_uniform(const char* name, const Color & color) {
212 | 	GLuint loc = glGetUniformLocation(program, name);
213 | 	glUniform4f(loc, color.rf(), color.gf(), color.bf(), color.af());
214 | }
215 | 
216 | void Shader::set_uniform(const char* name, const float num) {
217 | 	GLuint loc = glGetUniformLocation(program, name);
218 | 	glUniform1f(loc, num);
219 | }
220 | 
221 | void Shader::set_uniform(const char* name, const GLuint num) {
222 | 	GLuint loc = glGetUniformLocation(program, name);
223 | 	glUniform1i(loc, num);
224 | }
225 | 
226 | }
227 | 


--------------------------------------------------------------------------------