├── .gitignore
├── COPYING
├── Makefile
├── README.md
├── bitfont.h
├── contrib
├── Pandora
│ ├── Makefile
│ ├── PND_Resources
│ │ ├── DejaVuSansMono-Bold.ttf
│ │ ├── PXML.xml
│ │ ├── defconf
│ │ │ ├── config.txt
│ │ │ └── profile.txt
│ │ ├── icon.png
│ │ ├── picklelauncher
│ │ └── runme.sh
│ ├── PXML_schema.xsd
│ ├── README.txt
│ └── pnd_make.sh
└── nacl
│ ├── .gitignore
│ ├── README.md
│ ├── app.yaml
│ ├── build.sh
│ ├── chrome-app
│ ├── icon_128.png
│ └── manifest.json
│ ├── load81.html
│ ├── nacl.cc
│ └── static
│ ├── load81.css
│ ├── load81.js
│ └── load81.nmf
├── editor.c
├── editor.h
├── examples
├── 2dsim.lua
├── asteroids.lua
├── falldown.lua
├── flames.lua
├── helicopter.lua
├── keynames.lua
├── lines.lua
├── paint.lua
├── scorched.lua
├── sprite.lua
├── sprite.png
├── text.lua
└── triangles.lua
├── framebuffer.c
├── framebuffer.h
├── load81.c
├── load81.h
└── lua
├── COPYRIGHT
├── HISTORY
├── INSTALL
├── Makefile
├── README
├── doc
├── contents.html
├── cover.png
├── logo.gif
├── lua.1
├── lua.css
├── lua.html
├── luac.1
├── luac.html
├── manual.css
├── manual.html
└── readme.html
├── etc
├── Makefile
├── README
├── all.c
├── lua.hpp
├── lua.ico
├── lua.pc
├── luavs.bat
├── min.c
├── noparser.c
└── strict.lua
├── src
├── Makefile
├── lapi.c
├── lapi.h
├── lauxlib.c
├── lauxlib.h
├── lbaselib.c
├── lcode.c
├── lcode.h
├── ldblib.c
├── ldebug.c
├── ldebug.h
├── ldo.c
├── ldo.h
├── ldump.c
├── lfunc.c
├── lfunc.h
├── lgc.c
├── lgc.h
├── linit.c
├── liolib.c
├── llex.c
├── llex.h
├── llimits.h
├── lmathlib.c
├── lmem.c
├── lmem.h
├── loadlib.c
├── lobject.c
├── lobject.h
├── lopcodes.c
├── lopcodes.h
├── loslib.c
├── lparser.c
├── lparser.h
├── lstate.c
├── lstate.h
├── lstring.c
├── lstring.h
├── lstrlib.c
├── ltable.c
├── ltable.h
├── ltablib.c
├── ltm.c
├── ltm.h
├── lua.c
├── lua.h
├── luac.c
├── luaconf.h
├── lualib.h
├── lundump.c
├── lundump.h
├── lvm.c
├── lvm.h
├── lzio.c
├── lzio.h
└── print.c
└── test
├── README
├── bisect.lua
├── cf.lua
├── echo.lua
├── env.lua
├── factorial.lua
├── fib.lua
├── fibfor.lua
├── globals.lua
├── hello.lua
├── life.lua
├── luac.lua
├── printf.lua
├── readonly.lua
├── sieve.lua
├── sort.lua
├── table.lua
├── trace-calls.lua
├── trace-globals.lua
└── xd.lua
/.gitignore:
--------------------------------------------------------------------------------
1 | load81
2 | *.o
3 | lua/src/*.o
4 | lua/src/*.a
5 | lua/src/lua
6 | lua/src/luac
7 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012, Salvatore Sanfilippo. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4 |
5 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7 |
8 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | PKGS=sdl2 SDL2_gfx SDL2_image
2 | CFLAGS=-O2 -Wall -W -Ilua/src `pkg-config --cflags $(PKGS)`
3 | LDLIBS=lua/src/liblua.a -lm `pkg-config --libs $(PKGS)`
4 |
5 | all: load81
6 |
7 | load81: load81.o editor.o framebuffer.o lua/src/liblua.a
8 | editor.o: editor.c editor.h framebuffer.h
9 | framebuffer.o: framebuffer.c framebuffer.h bitfont.h
10 | load81.o: load81.c framebuffer.h editor.h load81.h
11 |
12 | lua/src/liblua.a:
13 | -(cd lua && $(MAKE) ansi)
14 |
15 | clean:
16 | rm -f load81 *.o
17 |
18 | distclean: clean
19 | -(cd lua && $(MAKE) clean)
20 |
21 | dep:
22 | $(CC) -MM *.c
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | README
2 | ===
3 |
4 | Load81 is an attempt at creating a Codea-inspired environment to teach
5 | children how to write Lua programs. It features a graphical programming
6 | environment and a Commodore-64 style integrated editor so that the programmer
7 | is confined into a friendly environment with a simple editor:
8 |
9 | 
10 |
11 | The following is a screenshot of the running program (examples/asteroids.lua).
12 | The programmer can currently switch between edit and play mode pressing the
13 | ESC key.
14 |
15 | 
16 |
17 | Load81 is written in ANSI C and uses `SDL` and `SDL_gfx` and `SDL_image`, so
18 | should compile on Mac OS X and Linux without issues. It should not be hard
19 | to port it to Windows.
20 |
21 | The coordinate system and the basic drawing functions are compatible with
22 | Codea (check http://twolivesleft.com/Codea/ for more information), but there
23 | is no support for stroke.
24 |
25 | There is no aim at Codea compatibility, but who is familiar with Codea should
26 | feel at home with Load81 in terms of API and structure of the program.
27 |
28 | I wrote it mainly because I and my children have fun with Codea but we don't
29 | have an iPad at home, and using a real keyboard sometimes can be less
30 | frustrating.
31 |
32 | The name Load81 originates from the fact that in popular Commodore home
33 | computers the command `LOAD "*",8,1` would load the first program on the disk
34 | starting from the file-specified memory location.
35 |
36 | USAGE
37 | ===
38 |
39 | Start Load81 with:
40 |
41 | ./load81 example.lua
42 |
43 | To switch between program and editor mode press the ESC key.
44 |
45 | Check the "examples" folder for small examples.
46 |
47 | PROGRAMMING INTERFACE
48 | ===
49 |
50 | Drawing functions:
51 |
52 | * fill(r,g,b,alpha): select the drawing color.
53 | * background(r,g,b): paint the whole background with the specified color.
54 | * rect(x,y,width,height): draw a rectangle at x,y (left-bottom corner).
55 | * ellipse(x,y,width,height): draw an ellipse centered at x,y.
56 | * line(x1,y1,x2,y2): draw a line from x1,y1 to x2,y2.
57 | * text(x,y,string): print the specified text at x,y using a bitmap font.
58 | * triangle(x1,y1,x2,y2,x3,y3): draw a triangle with the specified vertex.
59 | * getpixel(x,y): return the red,gree,blue value of the specified pixel.
60 | * sprite(file,x,y,[rotation],[antialiasing]): draw sprite at coordinates with the specified rotation (in degrees, default 0) and antialiasing (default false).
61 |
62 | Control functions:
63 |
64 | * setFPS(fps): Set the frame rate. For default it's set to 30 frames per second.
65 |
66 | KEYBOARD EVENTS
67 | ===
68 |
69 | To check if a key 'a' is pressed use:
70 |
71 | if keyboard.pressed['a'] then ...
72 |
73 | SDL Key symbol names are used. You can easily find how a given key is
74 | called using the following Lua program:
75 |
76 | function draw()
77 | for k,v in pairs(keyboard.pressed) do
78 | print(k)
79 | end
80 | end
81 |
82 | (You can find this program under the examples folder).
83 |
84 | LOW LEVEL KEYBOARD EVENTS
85 | ===
86 |
87 | It is also possible to trap low level SDL events accessing keyboard.state
88 | and keyboard.key fields of the keyboard table.
89 |
90 | keyboard.state is one of:
91 |
92 | "down" -> KEYDOWN event
93 | "up" -> KEYUP event
94 | "none" -> No event
95 |
96 | keyboard.key is set to the key pressed or released when state is different
97 | than "none".
98 |
99 | MOUSE EVENTS
100 | ===
101 |
102 | mouse.x and mouse.y gives you the current mouse coordinates. To check
103 | if a button is pressed use:
104 |
105 | if mouse.pressed['1'] then ...
106 |
107 | Mouse buttons are called '1', '2', '3', ... and so forth.
108 |
109 | LICENSE
110 | ===
111 |
112 | Load81 was written by Salvatore Sanfilippo and is released under the
113 | BSD two-clause license, see the COPYING file for more information.
114 |
115 | The load81 project is dedicated to Jack Tramiel, founder of Commodore.
116 |
--------------------------------------------------------------------------------
/contrib/Pandora/Makefile:
--------------------------------------------------------------------------------
1 | all: pnd-file
2 |
3 | pnd-file:
4 | rm -rf PND_Resources/examples/ && mkdir PND_Resources/examples/
5 | cp -rfv ../../examples/* PND_Resources/examples/
6 | cp ../../load81 PND_Resources/
7 | ./pnd_make.sh -c -d PND_Resources/ -x PND_Resources/PXML.xml -i PND_Resources/icon.png -p ./LOAD81.pnd
8 |
9 | clean:
10 | rm -rf PND_Resources/examples/
11 | rm -f PND_Resources/load81
12 | rm -f LOAD81.pnd
13 |
--------------------------------------------------------------------------------
/contrib/Pandora/PND_Resources/DejaVuSansMono-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antirez/load81/f3b4404c2ba9fe24dcad3fdc8679de9662fcc1f5/contrib/Pandora/PND_Resources/DejaVuSansMono-Bold.ttf
--------------------------------------------------------------------------------
/contrib/Pandora/PND_Resources/PXML.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | LOAD81
8 |
9 |
10 | SDL based Lua programming environment for kids, similar to Codea.
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | LOAD81
20 |
21 | LOAD81
22 |
23 | SDL based Lua programming environment for kids, similar to Codea.
24 |
25 | SDL based Lua programming environment for kids, similar to Codea.
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/contrib/Pandora/PND_Resources/defconf/profile.txt:
--------------------------------------------------------------------------------
1 | # Global Settings
2 | targetapp=LOAD81 by antirez, Pandora build by torpor
3 | filepath=./examples/
4 |
5 | # Command Settings
6 |
7 | # Extension Settings
8 | [lua]
9 | exepath=./load81 --full
10 | extarg=--width;0;%na%;800
11 | extarg=--height;0;%na%;480
12 | extarg=;0;%na%;%filename%
13 |
14 | # Custom Entries Settings
15 |
--------------------------------------------------------------------------------
/contrib/Pandora/PND_Resources/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antirez/load81/f3b4404c2ba9fe24dcad3fdc8679de9662fcc1f5/contrib/Pandora/PND_Resources/icon.png
--------------------------------------------------------------------------------
/contrib/Pandora/PND_Resources/picklelauncher:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antirez/load81/f3b4404c2ba9fe24dcad3fdc8679de9662fcc1f5/contrib/Pandora/PND_Resources/picklelauncher
--------------------------------------------------------------------------------
/contrib/Pandora/PND_Resources/runme.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | if [ ! -f "./profile.txt" ]; then
3 | cp -R defconf/* ./
4 | fi
5 | if [ $# -eq 0 ]
6 | then
7 | ./picklelauncher
8 | fi
9 |
--------------------------------------------------------------------------------
/contrib/Pandora/README.txt:
--------------------------------------------------------------------------------
1 |
2 | This is a build-tree for making a PND file for the Open Pandora game console. It includes a
3 | PickleLauncher binary pre-built for the OpenPandora. The purpose of this project is to
4 | create an easy-to-use distribution of LOAD81 for Open Pandora users. With this build-tree
5 | it should be very easy to make a distribution of LOAD81 as new features get added.
6 |
7 | References:
8 |
9 | Open Pandora console http://openpandora.org/
10 | PND file info http://pandorawiki.org/Pnd
11 | PickleLauncher http://pandorawiki.org/PickleLauncher
12 | http://sourceforge.net/projects/picklelauncher/
13 |
14 | Requirements:
15 | + An Open Pandora console
16 | + the CDEV tools PND file, available here:
17 | http://repo.openpandora.org/?page=detail&app=cdevtools.freamon.40n8e
18 |
19 | How to use:
20 |
21 | 1. Check out the LOAD81 sources onto your Open Pandora console somewhere sensible.
22 | 2. Execute the CDEV tools and get into the cdev shell (see CDEV docs)
23 | 3. Build LOAD81 on your Open Pandora (should be as simple as typing 'make' in the main LOAD81
24 | sources tree) & verify that the load81 binary is created for Open Pandora
25 | 4. 'cd contrib/Pandora' and type 'make' or 'make clean && make pnd-file'
26 |
27 | This will then produce the LOAD81.pnd file, bundled up and packaged with PickleLauncher for
28 | selecting files, the load81 executable itself, and the load81 examples/ tree for easy use. This
29 | PND file can then be shared on repo's/forums/etc. for Open Pandora users to get their LOAD81
30 | habits formed! :)
31 |
32 | Good luck!
33 |
34 |
35 | --
36 | Questions / Comments about this contrib: seclorum@me.com (torpor on OPB forums)
37 | Questions / Comments about LOAD81: antirez@gmail.com
38 | Questions / Comments about PickleLauncher: http://sourceforge.net/projects/picklelauncher/
39 |
40 |
--------------------------------------------------------------------------------
/contrib/nacl/.gitignore:
--------------------------------------------------------------------------------
1 | *.nexe
2 |
--------------------------------------------------------------------------------
/contrib/nacl/README.md:
--------------------------------------------------------------------------------
1 | # Load81 Port to Google Native Client
2 |
3 | ## Requirements
4 |
5 | * Google Chrome 15 or higher.
6 | * Google App Engine Python SDK.
7 | * Native Client SDK.
8 | * NaclPorts with SDL and SDL_gfx built for i686 and x86\_64.
9 | * NACL\_SDK\_ROOT environment variable set.
10 |
11 | ## Building
12 |
13 | Ensure the above requirements are met, then run contrib/nacl/build.sh.
14 |
15 | ## Testing
16 |
17 | Run dev_appserver.py contrib/nacl to start an HTTP server on port 8080. Follow
18 | the instructions in the [Native Client documentation][1] to enable Native
19 | Client in Chrome 15+. Now, open http://localhost:8080/ in Chrome and Load81
20 | should start.
21 |
22 | [1]: https://developers.google.com/native-client/pepper16/devguide/devcycle/running#Local
23 |
24 | ## Publishing
25 |
26 | You will need to create a Google App Engine application first. Then:
27 |
28 | appcfg.py -A $YOUR_APP_NAME update contrib/nacl
29 |
30 | Now you need to create a Chrome application. Follow the instructions at the
31 | [Chrome Developer's Guide][2], using contrib/nacl/chrome-app/manifest.json as
32 | a template.
33 |
34 | [2]: http://code.google.com/chrome/apps/docs/developers_guide.html
35 |
36 | ## TODO
37 |
38 | * Support loading and saving local files.
39 |
--------------------------------------------------------------------------------
/contrib/nacl/app.yaml:
--------------------------------------------------------------------------------
1 | application: load81
2 | version: 1
3 | runtime: python27
4 | api_version: 1
5 | threadsafe: true
6 |
7 | handlers:
8 | - url: /
9 | static_files: load81.html
10 | upload: load81.html
11 | - url: /static
12 | static_dir: static
13 | - url: /examples
14 | static_dir: examples
15 | - url: /load81-i686-nacl.nexe
16 | static_files: load81-i686-nacl.nexe
17 | upload: load81-i686-nacl.nexe
18 | - url: /load81-x86_64-nacl.nexe
19 | static_files: load81-x86_64-nacl.nexe
20 | upload: load81-x86_64-nacl.nexe
21 |
--------------------------------------------------------------------------------
/contrib/nacl/build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # TODO use the common Makefile instead of duplicating it.
3 | set -ex
4 |
5 | if [ -z $NACL_SDK_ROOT ]
6 | then
7 | echo "NACL_SDK_ROOT must be set."
8 | echo "example: NACL_SDK_ROOT=$HOME/nacl-sdk-update/pepper_15"
9 | exit 1
10 | fi
11 |
12 | TOOLCHAIN=$NACL_SDK_ROOT/toolchain/linux_x86_newlib
13 | NACL_ROOT=$(dirname $(which $0))
14 | ROOT=$(readlink -f $NACL_ROOT/../..)
15 | PKGS="sdl SDL_gfx"
16 |
17 | rm -f $NACL_ROOT/examples
18 | ln -s $ROOT/examples $NACL_ROOT/examples
19 |
20 | for HOST in i686-nacl x86_64-nacl
21 | do
22 | cd $NACL_ROOT
23 | export PKG_CONFIG_PATH=$TOOLCHAIN/$HOST/usr/lib/pkgconfig
24 | export CC=$HOST-gcc
25 | BFDARCH=i386
26 | if [ $HOST == i686-nacl ]; then
27 | BFDNAME=elf32-nacl
28 | else
29 | BFDNAME=elf64-nacl
30 | fi
31 | CFLAGS="-O2 -Wall -W -D main=load81_main `pkg-config --cflags $PKGS`"
32 | LDFLAGS=""
33 | for X in read write open close seek mount; do
34 | LDFLAGS="$LDFLAGS -Xlinker --wrap -Xlinker $X"
35 | done
36 | LIBS="`pkg-config --libs $PKGS` -llua -lm -lppapi -lppapi_cpp -lnacl-mounts -lstdc++ -lnosys"
37 | SRCS="$ROOT/load81.c $ROOT/editor.c $ROOT/framebuffer.c nacl.cc"
38 | $CC $CFLAGS $LDFLAGS $SRCS $LIBS -o load81-$HOST.nexe
39 | $HOST-strip load81-$HOST.nexe
40 | done
41 |
42 | echo Built successfully
43 |
--------------------------------------------------------------------------------
/contrib/nacl/chrome-app/icon_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antirez/load81/f3b4404c2ba9fe24dcad3fdc8679de9662fcc1f5/contrib/nacl/chrome-app/icon_128.png
--------------------------------------------------------------------------------
/contrib/nacl/chrome-app/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rlane-load81",
3 | "description": "Lua programming environment for kids similar to Codea",
4 | "version": "0.0.0.1",
5 | "icons": {
6 | "128": "icon_128.png"
7 | },
8 | "app": {
9 | "urls": [
10 | "http://rlane-load81.appspot.com/"
11 | ],
12 | "launch": {
13 | "web_url": "http://rlane-load81.appspot.com/"
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/contrib/nacl/load81.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/contrib/nacl/nacl.cc:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | #include
16 | #include
17 | #include
18 |
19 | extern "C" {
20 | extern int load81_main(int argc, char *argv[]);
21 | extern int mount(const char *type, const char *dir, int flags, void *data);
22 | extern char _binary_example_lua_start[];
23 | extern int _binary_example_lua_size;
24 | }
25 |
26 | /*
27 | * Copied from earth sample in naclports.
28 | */
29 | class Load81Instance : public pp::Instance {
30 | public:
31 | explicit Load81Instance(PP_Instance instance)
32 | : pp::Instance(instance),
33 | sdl_main_thread_(0),
34 | width_(0),
35 | height_(0) {
36 | printf("PluginInstance\n");
37 | }
38 |
39 | ~Load81Instance() {
40 | if (sdl_main_thread_) {
41 | pthread_join(sdl_main_thread_, NULL);
42 | }
43 | }
44 |
45 | virtual void DidChangeView(const pp::Rect& position, const pp::Rect& clip) {
46 | printf("did change view, new %dx%d, old %dx%d\n",
47 | position.size().width(), position.size().height(),
48 | width_, height_);
49 |
50 | if (position.size().width() == width_ &&
51 | position.size().height() == height_)
52 | return; // Size didn't change, no need to update anything.
53 | }
54 |
55 | bool HandleInputEvent(const pp::InputEvent& event) {
56 | SDL_NACL_PushEvent(event);
57 | return true;
58 | }
59 |
60 | void HandleMessage(const pp::Var& message) {
61 | fprintf(stderr, "HandleMessage\n");
62 | std::string data = message.AsString();
63 | int fd = open("program.lua", O_CREAT | O_WRONLY);
64 | if (fd < 0) {
65 | perror("open");
66 | return;
67 | }
68 |
69 | if (write(fd, data.c_str(), data.length()) < 0) {
70 | perror("write");
71 | return;
72 | }
73 |
74 | if (close(fd) < 0) {
75 | perror("close");
76 | return;
77 | }
78 |
79 | SDL_NACL_SetInstance(pp_instance(), 800, 600);
80 | int lval = SDL_Init(SDL_INIT_VIDEO);
81 | assert(lval >= 0);
82 | pthread_create(&sdl_main_thread_, NULL, sdl_thread, this);
83 | }
84 |
85 | bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
86 | if (RequestFilteringInputEvents(PP_INPUTEVENT_CLASS_KEYBOARD|PP_INPUTEVENT_CLASS_WHEEL)) {
87 | throw std::runtime_error("failed to request filtering input events");
88 | }
89 |
90 | if (RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE)) {
91 | throw std::runtime_error("failed to request input events");
92 | }
93 |
94 | return true;
95 | }
96 |
97 | private:
98 | pthread_t sdl_main_thread_;
99 | int width_;
100 | int height_;
101 |
102 | static void* sdl_thread(void* param) {
103 | char argv0[] = "load81";
104 | char argv1[] = "program.lua";
105 | char argv2[] = "--fps";
106 | char *argv[] = { argv0, argv1, argv2, NULL };
107 | load81_main(3, argv);
108 | return NULL;
109 | }
110 | };
111 |
112 | class Load81Module : public pp::Module {
113 | public:
114 | Load81Module() : pp::Module() {}
115 |
116 | virtual ~Load81Module() {
117 | }
118 |
119 | virtual bool Init() {
120 | return true;
121 | }
122 |
123 | virtual pp::Instance* CreateInstance(PP_Instance instance) {
124 | return new Load81Instance(instance);
125 | }
126 | };
127 |
128 | namespace pp {
129 | Module* CreateModule() {
130 | return new Load81Module();
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/contrib/nacl/static/load81.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | background-color: #B2B0B0;
5 | }
6 |
7 | #menu {
8 | position: absolute;
9 | left: 0;
10 | top: 0;
11 | width: 100%;
12 | background-color: #181818;
13 | z-index: 70;
14 | box-shadow: 0px 3px 2px #808080;
15 | cursor: default;
16 | }
17 |
18 |
19 | #menu div {
20 | display: block;
21 | float: left;
22 | padding-left: 10px;
23 | padding-right: 10px;
24 | padding-top: 5px;
25 | padding-bottom: 5px;
26 | cursor: pointer;
27 | font-weight: bold;
28 | color: #FF7E00;
29 | }
30 |
31 | #menu div:hover {
32 | background-color: #282828;
33 | }
34 |
35 | .screen {
36 | position: absolute;
37 | opacity: 0.0;
38 | left: 50%;
39 | top: 50%;
40 | padding-left: 40px;
41 | padding-right: 40px;
42 | padding-top: 10px;
43 | padding-bottom: 10px;
44 | width: 720px;
45 | min-height: 580px;
46 | margin-left: -400px;
47 | margin-top: -300px;
48 | z-index: 50;
49 | background: white;
50 | border: solid 1px black;
51 | box-shadow: 3px 3px 2px #808080;
52 | }
53 |
54 | #play-screen {
55 | padding: 0;
56 | width: 800px;
57 | height: 600px;
58 | }
59 |
60 | #nacl_module {
61 | width: 800px;
62 | height: 600px;
63 | }
64 |
65 | #status {
66 | position: absolute;
67 | display: none;
68 | left: 50%;
69 | top: 50%;
70 | width: 300px;
71 | margin-left: -150px;
72 | margin-top: -20px;
73 | z-index: 100;
74 | text-align: center;
75 | background-color: rgba(100, 100, 100, 1);
76 | border: solid 1px black;
77 | padding: 4px;
78 | color: black;
79 | }
80 |
--------------------------------------------------------------------------------
/contrib/nacl/static/load81.js:
--------------------------------------------------------------------------------
1 | var initial_script = "examples/asteroids.lua";
2 |
3 | $(document).ready(function(){
4 | var nacl_module = null;
5 | var src = null;
6 |
7 | function main() {
8 | xhr = new XMLHttpRequest();
9 | xhr.open("GET", initial_script);
10 | xhr.onload = function (event) {
11 | // TODO check for failure
12 | start_game(xhr.responseText);
13 | }
14 | xhr.send();
15 | }
16 |
17 | function switch_screen(id) {
18 | $(".screen").css({ "z-index": 50 });
19 | $(".screen").animate({ opacity:0.0 }, { queue: false, duration: "slow" });
20 | $("#"+id).css({ "z-index": 60 });
21 | $("#"+id).animate({ opacity:1.0 }, { queue: false, duration: "slow" });
22 | }
23 |
24 | function start_game(_src) {
25 | if (nacl_module) {
26 | $(nacl_module).remove();
27 | nacl_module = null;
28 | }
29 |
30 | nacl_html = '';
35 |
36 | var e = document.createElement("embed");
37 | e.id = "nacl_module";
38 | e.name = "nacl_module";
39 | e.src = "static/load81.nmf";
40 | e.type = "application/x-nacl";
41 | e.tabIndex = -1;
42 | $("#play-screen").append(e);
43 | nacl_module = e;
44 | src = _src;
45 | }
46 |
47 | /*
48 | * Native Client events
49 | */
50 |
51 | function moduleDidStartLoad() {
52 | $("#status").html("Loading...");
53 | $("#status").show();
54 | }
55 |
56 | function moduleLoadProgress(event) {
57 | if (event.total != 0) {
58 | var load_percent = Math.round(100.0 * event.loaded / event.total);
59 | $("#status").html("Loading: " + load_percent + "%");
60 | }
61 | }
62 |
63 | function moduleLoadError() {
64 | }
65 |
66 | function moduleLoadAbort() {
67 | }
68 |
69 | function moduleDidLoad() {
70 | nacl_module.postMessage(src);
71 | switch_screen("play-screen");
72 | nacl_module.focus();
73 | }
74 |
75 | function moduleDidEndLoad() {
76 | var lastError = event.target.lastError;
77 | if (lastError != undefined && lastError != "") {
78 | $("#status").html(lastError)
79 | } else {
80 | $("#status").fadeOut("slow")
81 | switch_screen("play-screen");
82 | }
83 | }
84 |
85 | function handleMessage(message_event) {
86 | console.log(message_event.data);
87 | }
88 |
89 | var listener = document.getElementById('play-screen')
90 | listener.addEventListener('loadstart', moduleDidStartLoad, true);
91 | listener.addEventListener('progress', moduleLoadProgress, true);
92 | listener.addEventListener('error', moduleLoadError, true);
93 | listener.addEventListener('abort', moduleLoadAbort, true);
94 | listener.addEventListener('load', moduleDidLoad, true);
95 | listener.addEventListener('loadend', moduleDidEndLoad, true);
96 | listener.addEventListener('message', handleMessage, true);
97 |
98 | /*
99 | * Menu buttons
100 | */
101 |
102 | $("#play").click(function(event) {
103 | switch_screen("play-screen");
104 | if (nacl_module) {
105 | nacl_module.focus();
106 | }
107 | });
108 |
109 | $("#help").click(function(event) {
110 | switch_screen("help-screen");
111 | });
112 |
113 | $("#load").click(function(event) {
114 | switch_screen("load-screen");
115 | });
116 |
117 | $("#save").click(function(event) {
118 | // TODO
119 | alert("save!");
120 | });
121 |
122 |
123 | /*
124 | * Load screen
125 | */
126 |
127 | $("#uploader").change(function(event) {
128 | var file = event.target.files[0];
129 | var reader = new FileReader();
130 | reader.onload = function(evt) {
131 | console.log(["uploaded", evt]);
132 | var code = reader.result;
133 | start_game(code);
134 | };
135 | reader.readAsBinaryString(file);
136 | });
137 |
138 |
139 | main();
140 | });
141 |
--------------------------------------------------------------------------------
/contrib/nacl/static/load81.nmf:
--------------------------------------------------------------------------------
1 | {
2 | "program": {
3 | "x86-64": {"url": "../load81-x86_64-nacl.nexe"},
4 | "x86-32": {"url": "../load81-i686-nacl.nexe"}
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/editor.h:
--------------------------------------------------------------------------------
1 | #ifndef EDITOR_H
2 | #define EDITOR_H
3 |
4 | #include "framebuffer.h"
5 |
6 | #define POWEROFF_BUTTON_X (E.fb->width-18)
7 | #define POWEROFF_BUTTON_Y 18
8 | #define SAVE_BUTTON_X (E.fb->width-E.margin_right-13)
9 | #define SAVE_BUTTON_Y (E.fb->height-16)
10 | #define EDITOR_FPS 30
11 |
12 | /* Syntax highlight types */
13 | #define HL_NORMAL 0
14 | #define HL_ERROR 1
15 | #define HL_COMMENT 2
16 | #define HL_KEYWORD 3
17 | #define HL_STRING 4
18 | #define HL_NUMBER 5
19 | #define HL_FUNCDEF 6
20 | #define HL_LIB 7
21 |
22 | #define HL_NORMAL_COLOR {165,165,255}
23 | #define HL_ERROR_COLOR {255,0,0}
24 | #define HL_COMMENT_COLOR {180,180,0}
25 | #define HL_KEYWORD_COLOR {50,255,50}
26 | #define HL_STRING_COLOR {0,255,255}
27 | #define HL_NUMBER_COLOR {225,100,100}
28 | #define HL_FUNCDEF_COLOR {255,255,255}
29 | #define HL_LIB_COLOR {255,0,255}
30 |
31 | typedef struct erow {
32 | int size; /* Size of the row, excluding the null term. */
33 | char *chars; /* Row content. */
34 | unsigned char *hl; /* Syntax highlight type for each character. */
35 | } erow;
36 |
37 | typedef struct keyState {
38 | int ksym;
39 | int counter;
40 | } keyState;
41 |
42 | typedef struct hlcolor {
43 | int r,g,b;
44 | } hlcolor;
45 |
46 | #define KEY_MAX 32 /* Max number of key events we can store at the same time. */
47 | struct editorConfig {
48 | int cx,cy; /* Cursor x and y position in characters */
49 | unsigned char cblink; /* Show cursor if (cblink & 0x80) == 0 */
50 | int screenrows; /* Number of rows that we can show */
51 | int screencols; /* Number of cols that we can show */
52 | int margin_top, margin_bottom, margin_left, margin_right;
53 | int rowoff; /* Row offset on screen */
54 | int coloff; /* Column offset on screen */
55 | int numrows; /* Number of rows */
56 | erow *row; /* Rows */
57 | time_t lastevent; /* Last event time, so we can go standby */
58 | keyState key[KEY_MAX]; /* Remember if a key is pressed / repeated. */
59 | int dirty; /* File modified but not saved. */
60 | char *filename; /* Currently open filename */
61 | frameBuffer *fb; /* Framebuffer */
62 | char *err; /* Error string to display, or NULL if no error. */
63 | int errline; /* Error line to highlight if err != NULL. */
64 | };
65 |
66 | /* ================================ Prototypes ============================== */
67 |
68 | /* editor.c */
69 | void initEditor(frameBuffer *fb, int mt, int mb, int ml, int mr);
70 | char *editorRowsToString(int *buflen);
71 | int editorOpen(char *filename);
72 | int editorSave(char *filename);
73 | int editorEvents(void);
74 | void editorSetError(const char *err, int line);
75 | void editorClearError(void);
76 | int editorFileWasModified(void);
77 | void editorRun(void);
78 |
79 | #endif /* EDITOR_H */
80 |
--------------------------------------------------------------------------------
/examples/2dsim.lua:
--------------------------------------------------------------------------------
1 | -- 2dsim, very basic 2D physics simulator
2 | -- Written by Salvatore Sanfilippo and Enea Sanfilippo
3 |
4 | function setup()
5 | -- x and y are the current ball position.
6 | x = WIDTH/2
7 | y = HEIGHT/2
8 | -- vx, vy is the velocity.
9 | vx = 0
10 | vy = 0
11 | -- ax, ay is the acceleration.
12 | ax = 0
13 | ay = 0
14 | -- ground is the y coordinate of the ground line.
15 | -- radius is the radius of the ball.
16 | GROUND = 50
17 | RADIUS = 10
18 | end
19 |
20 | function draw()
21 | -- Retrace the scene, writing the ground as a blue box.
22 | background(0,0,0)
23 | fill(0,0,255,1)
24 | rect(0,0,WIDTH,GROUND-RADIUS)
25 |
26 | -- Recompute the position using the velocity, also recompute the
27 | -- velocity using the acceleration.
28 | x = (x + vx) % WIDTH
29 | y = y + vy
30 | vx = vx + ax
31 | vy = vy + ay
32 |
33 | -- Let the user accelerate the body using arrow keys.
34 | ax = 0
35 | ay = 0
36 | if keyboard.pressed['left'] then
37 | ax = -1
38 | end
39 | if keyboard.pressed['right'] then
40 | ax = 1
41 | end
42 | if keyboard.pressed['up'] then
43 | ay = 1
44 | end
45 | if keyboard.pressed['down'] then
46 | ay = -1
47 | end
48 |
49 | -- Simulate gravity, always adding a negative Y acceleration.
50 | ay = ay - 0.5
51 |
52 | -- Detect contact with the ground.
53 | if y < GROUND then
54 | -- When the ball hits the ground, invert the sign of the y
55 | -- velocity in order to simulate bouncing.
56 | -- However only let 50% of the speed to be retained.
57 | y = GROUND
58 | vy = -vy * 0.5
59 | -- Filter small y velocity to avoid the ball to bounce forever.
60 | if (math.abs(vy) < 1) then
61 | vy = 0
62 | end
63 | end
64 |
65 | -- Simulate friction with the ground by reducign the X speed when
66 | -- the ball touches the ground.
67 | if y == GROUND then
68 | vx = vx * 0.95
69 | end
70 |
71 | -- Draw the ball at the new position.
72 | fill(255,255,0,1)
73 | ellipse(x,y,RADIUS,RADIUS)
74 | end
75 |
--------------------------------------------------------------------------------
/examples/asteroids.lua:
--------------------------------------------------------------------------------
1 | -- Simple Asteroids-alike game.
2 | -- Copyright (C) 2012 Salvatore Sanfilippo.
3 | -- This code is released under the BSD two-clause license.
4 |
5 | function setup()
6 | ticks = 0 -- Number of iteration of the program
7 | shipx = WIDTH/2 -- Ship x position
8 | shipy = HEIGHT/2 -- Ship y position
9 | shipa = 0 -- Ship rotation angle
10 | shipvx = 0 -- Ship x velocity
11 | shipvy = 0 -- Ship y velocity
12 | bullets = {} -- An array of bullets
13 | asteroids = {} -- An array of asteroids
14 | asteroids_num = 0; -- Number of asteroids on screen
15 | asteroids_max = 2; -- Max number of asteroids to show
16 | last_bullet_ticks = 0 -- Ticks at the time the last bullet was fired
17 |
18 | -- Populate the game with asteroids at start
19 | while(asteroids_num < asteroids_max) do
20 | addAsteroid()
21 | end
22 | end
23 |
24 | -- The following functions move objects adding the velocity
25 | -- to the position at every iteration.
26 |
27 | function moveShip()
28 | shipx = (shipx + shipvx) % WIDTH
29 | shipy = (shipy + shipvy) % HEIGHT
30 | end
31 |
32 | function moveBullets()
33 | local i,b
34 | for i,b in pairs(bullets) do
35 | b.x = b.x+b.vx
36 | b.y = b.y+b.vy
37 | b.ttl = b.ttl - 1
38 | if b.ttl == 0 then bullets[i] = nil end
39 | end
40 | end
41 |
42 | function moveAsteroids()
43 | local i,a
44 | for i,a in pairs(asteroids) do
45 | a.x = (a.x+a.vx) % WIDTH
46 | a.y = (a.y+a.vy) % HEIGHT
47 | end
48 | end
49 |
50 | -- Add an asteroid. Create a random asteroid so that it's
51 | -- not too close to the ship.
52 |
53 | function addAsteroid()
54 | local x,y,a,ray
55 | while true do
56 | x = math.random(WIDTH)
57 | y = math.random(HEIGHT)
58 | ray = math.random(20,40)
59 | if math.abs(x-shipx) > ray and
60 | math.abs(y-shipy) > ray then
61 | break
62 | end
63 | end
64 | a = { x = x, y = y, vx = math.random()*2, vy = math.random()*2,
65 | ray = ray }
66 | table.insert(asteroids,a)
67 | asteroids_num = asteroids_num + 1
68 | end
69 |
70 | -- Fire a bullet with velocity 2,2 and the same orientation
71 | -- as the ship orientation.
72 |
73 | function fire()
74 | local b
75 | -- Don't fire again if we already fired
76 | -- less than 5 iterations ago.
77 | if ticks - last_bullet_ticks < 5 then return end
78 | b = { x = shipx, y = shipy,
79 | vx = shipvx+(4*math.sin(shipa)),
80 | vy = shipvy+(4*math.cos(shipa)),
81 | ttl=300 }
82 | -- Make sure that the bullet originaes from ship head
83 | b.x = b.x+(20*math.sin(shipa))
84 | b.y = b.y+(20*math.cos(shipa))
85 | -- Finally insert the bullet in the table of bullets
86 | table.insert(bullets,b)
87 | last_bullet_ticks = ticks
88 | end
89 |
90 | -- Draw the screen, move objects, detect collisions.
91 | function draw()
92 | ticks = ticks+1
93 |
94 | -- Handle keyboard events.
95 | if keyboard.pressed['left'] then shipa = shipa - 0.1 end
96 | if keyboard.pressed['right'] then shipa = shipa + 0.1 end
97 | if keyboard.pressed['up'] then
98 | shipvx = shipvx + 0.15*math.sin(shipa)
99 | shipvy = shipvy + 0.15*math.cos(shipa)
100 | end
101 | if keyboard.pressed['space'] then fire() end
102 |
103 | -- Create a new asteroid from time to time if needed
104 | if asteroids_num < asteroids_max and (ticks % 200) == 0 then
105 | while(asteroids_num < asteroids_max) do addAsteroid() end
106 | end
107 |
108 | -- Move all the objects of the game.
109 | moveShip()
110 | moveBullets()
111 | moveAsteroids()
112 | checkBulletCollision()
113 |
114 | -- Draw the current game screen.
115 | background(0,0,0)
116 | drawBullets()
117 | drawAsteroids()
118 | drawShip(shipx,shipy,shipa)
119 | end
120 |
121 | -- Math formula to rotate a point counterclockwise, with
122 | -- rotation center at 0,0.
123 |
124 | function rotatePoint(x,y,a)
125 | return x*math.cos(a)-y*math.sin(a),
126 | y*math.cos(a)+x*math.sin(a)
127 | end
128 |
129 | -- Draw the ship, that is composed of three vertex,
130 | -- rotating the vertexes using rotatePoint().
131 |
132 | function drawShip(x,y,a)
133 | local triangles = {}
134 | table.insert(triangles,
135 | {x0 = -10, y0 = -10, x1 = 0, y1 = 20, x2 = 10, y2 = -10,
136 | r = 255, g = 0, b = 0, alpha = 1 })
137 | if keyboard.pressed['up'] then
138 | table.insert(triangles,
139 | {x0 = -5, y0 = -10, x1 = 0, y1 = math.random(-25,-20), x2 = 5, y2 = -10,
140 | r = 255, g = 255, b = 0, alpha = 1 })
141 | end
142 | for i,t in pairs(triangles) do
143 | fill(t.r,t.g,t.b,t.alpha)
144 | t.x0,t.y0 = rotatePoint(t.x0,t.y0,-a);
145 | t.x1,t.y1 = rotatePoint(t.x1,t.y1,-a);
146 | t.x2,t.y2 = rotatePoint(t.x2,t.y2,-a);
147 | triangle(x+t.x0,y+t.y0,x+t.x1,y+t.y1,x+t.x2,y+t.y2)
148 | end
149 | end
150 |
151 | -- Draw a bullet, that's just a single pixel.
152 |
153 | function drawBullets()
154 | local i,b
155 | for i,b in pairs(bullets) do
156 | fill(255,255,255,1)
157 | rect(b.x-1,b.y-1,3,3)
158 | end
159 | end
160 |
161 | -- Draw an asteroid.
162 |
163 | function drawAsteroids()
164 | local i,a
165 | for i,a in pairs(asteroids) do
166 | fill(150,150,150,1)
167 | ellipse(a.x,a.y,a.ray,a.ray)
168 | end
169 | end
170 |
171 | -- This function detects the collision between a bullet
172 | -- and an asteroid, and removes both the bullet and the
173 | -- asteroid from the game when they collide.
174 |
175 | function checkBulletCollision()
176 | local i,j,b,a,del_asteroids,del_bullets
177 | del_asteroids = {}
178 | del_bullets = {}
179 | for i,b in pairs(bullets) do
180 | for j,a in pairs(asteroids) do
181 | local distance,dx,dy
182 | dx = a.x-b.x
183 | dy = a.y-b.y
184 | distance = math.sqrt((dx*dx)+(dy*dy))
185 | if distance < a.ray then
186 | del_asteroids[j] = true
187 | del_bullets[i] = true
188 | break
189 | end
190 | end
191 | end
192 | for i,b in pairs(del_bullets) do
193 | table.remove(bullets,i)
194 | end
195 | for i,a in pairs(del_asteroids) do
196 | table.remove(asteroids,i)
197 | asteroids_num = asteroids_num - 1
198 | if asteroids_num == 0 then
199 | asteroids_max = asteroids_max + 1
200 | end
201 | end
202 | end
203 |
--------------------------------------------------------------------------------
/examples/flames.lua:
--------------------------------------------------------------------------------
1 | -- Flames.lua, contributed by pmprog in the OpenPandora board.
2 | -- See http://boards.openpandora.org/index.php?/topic/7405-here-is-a-pnd-for-load81/
3 |
4 | function setup()
5 | local x, y, l
6 |
7 | MaxFlames = 150
8 | FlameLife = 40
9 | FlameSize = 10
10 | refreshCount = 0
11 | skipCount = 0
12 | Flames = { }
13 |
14 | for i=1,MaxFlames do
15 | x = math.random(WIDTH/3) + (WIDTH/3)
16 | y = math.random(FlameSize)
17 | l = math.random(FlameLife)
18 | a = { x = x, y = y, l = l }
19 | table.insert(Flames,a)
20 | end
21 | end
22 |
23 | function draw()
24 | local i, f, minMove
25 |
26 | background(0,0,0)
27 | for i,f in pairs(Flames) do
28 | if f.l > 35 then
29 | fill(255, 255, 255, 0.9)
30 | minMove = 0
31 | elseif f.l > 30 then
32 | fill(255, 255, 192, 0.8)
33 | minMove = 1
34 | elseif f.l > 20 then
35 | fill(255, 192, 128, 0.7)
36 | minMove = 2
37 | elseif f.l > 10 then
38 | fill(220, 128, 100, 0.5)
39 | minMove = 3
40 | else
41 | fill(160, 128, 80, 0.3)
42 | minMove = 5
43 | end
44 |
45 | ellipse(f.x,f.y,FlameSize,FlameSize)
46 | f.l = f.l - math.random(3)
47 | if f.l <= 0 then
48 | f.x = math.random(WIDTH/3) + (WIDTH/3)
49 | f.y = math.random(FlameSize)
50 | f.l = FlameLife
51 | else
52 | f.y = f.y + (math.random(6) + minMove)
53 | f.x = f.x + math.random(7) - 3
54 | end
55 | end
56 | end
57 |
58 |
--------------------------------------------------------------------------------
/examples/keynames.lua:
--------------------------------------------------------------------------------
1 | function setup()
2 | print("Press any key to see the corresponding name.")
3 | end
4 |
5 | function draw()
6 | for k,v in pairs(keyboard.pressed) do
7 | print(k)
8 | end
9 | end
10 |
--------------------------------------------------------------------------------
/examples/lines.lua:
--------------------------------------------------------------------------------
1 | function setup()
2 | background(0,0,0);
3 | end
4 |
5 | function draw()
6 | fill(math.random(255),math.random(255),math.random(255),math.random())
7 | line (math.random(WIDTH),math.random(HEIGHT),
8 | math.random(WIDTH),math.random(HEIGHT))
9 | end
10 |
--------------------------------------------------------------------------------
/examples/paint.lua:
--------------------------------------------------------------------------------
1 | function setup()
2 | background(0,0,0)
3 | end
4 |
5 | function draw()
6 | if mouse.pressed['1'] then
7 | fill(255,0,0,.2)
8 | else
9 | fill(0,0,255,.2)
10 | end
11 | ellipse(mouse.x,mouse.y,30,30)
12 | end
13 |
--------------------------------------------------------------------------------
/examples/sprite.lua:
--------------------------------------------------------------------------------
1 | local t, x = 0, 0
2 |
3 | function draw()
4 | background(0, 0, 0)
5 | local c = math.abs(math.cos(2*3.14*t));
6 | local y = 0.5*HEIGHT*c/math.exp(0.8*t);
7 |
8 | sprite("examples/sprite.png", x, y,t*-150);
9 | x = x + 3
10 | t = t + 0.01
11 |
12 | if (x > WIDTH) then
13 | t, x = 0, 0
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/examples/sprite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antirez/load81/f3b4404c2ba9fe24dcad3fdc8679de9662fcc1f5/examples/sprite.png
--------------------------------------------------------------------------------
/examples/text.lua:
--------------------------------------------------------------------------------
1 | function draw()
2 | background(0,0,0)
3 | fill(100,50,250,1)
4 | text(20,HEIGHT-40,"Please, enter this window with your mouse pointer.")
5 | fill(255,0,0,1)
6 | text(mouse.x,mouse.y,"Hello World!")
7 | fill(200,200,200,1)
8 | text(0,0,string.format("Mouse is at x:%s y:%s",mouse.x,mouse.y))
9 | end
10 |
--------------------------------------------------------------------------------
/examples/triangles.lua:
--------------------------------------------------------------------------------
1 | function setup()
2 | background(0,0,0);
3 | end
4 |
5 | function draw()
6 | fill(math.random(255),math.random(255),math.random(255),math.random())
7 | triangle(math.random(WIDTH),math.random(HEIGHT),
8 | math.random(WIDTH),math.random(HEIGHT),
9 | math.random(WIDTH),math.random(HEIGHT))
10 | end
11 |
--------------------------------------------------------------------------------
/framebuffer.h:
--------------------------------------------------------------------------------
1 | #ifndef FRAMEBUFFER_H
2 | #define FRAMEBUFFER_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #define FONT_WIDTH 16
14 | #define FONT_HEIGHT 16
15 | #define FONT_KERNING 10
16 |
17 | typedef struct frameBuffer {
18 | int width;
19 | int height;
20 | SDL_Window *screen;
21 | SDL_Renderer *renderer;
22 | SDL_Texture *texture;
23 | FPSmanager fps_mgr;
24 | } frameBuffer;
25 |
26 | /* Frame buffer */
27 | frameBuffer *createFrameBuffer(int width, int height, int fullscreen);
28 | void presentFrameBuffer(frameBuffer *fb);
29 |
30 | /* Drawing primitives */
31 | void setPixelWithAlpha(frameBuffer *fb, int x, int y, int r, int g, int b, int alpha);
32 | void fillBackground(frameBuffer *fb, int r, int g, int b);
33 | void drawHline(frameBuffer *fb, int x1, int x2, int y, int r, int g, int b, int alpha);
34 | void drawEllipse(frameBuffer *fb, int xc, int yc, int radx, int rady, int r, int g, int b, int alpha);
35 | void drawBox(frameBuffer *fb, int x1, int y1, int x2, int y2, int r, int g, int b, int alpha);
36 | void drawTriangle(frameBuffer *fb, int x1, int y1, int x2, int y2, int x3, int y3, int r, int g, int b, int alpha);
37 | void drawLine(frameBuffer *fb, int x1, int y1, int x2, int y2, int r, int g, int b, int alpha);
38 |
39 | /* Bitmap font */
40 | void bfLoadFont(char **c);
41 | void bfWriteChar(frameBuffer *fb, int xp, int yp, int c, int r, int g, int b, int alpha);
42 | void bfWriteString(frameBuffer *fb, int xp, int yp, const char *s, int len, int r, int g, int b, int alpha);
43 |
44 | /* Sprites */
45 | void spriteBlit(frameBuffer *fb, void *sprite, int x, int y, int angle, int aa);
46 | void *spriteLoad(lua_State *L, const char *filename);
47 | void initSpriteEngine(lua_State *L);
48 |
49 | #endif /* FRAMEBUFFER_H */
50 |
--------------------------------------------------------------------------------
/load81.h:
--------------------------------------------------------------------------------
1 | #ifndef LOAD81_H
2 | #define LOAD81_H
3 |
4 | #include "framebuffer.h"
5 |
6 | /* ================================ Defaults ================================ */
7 |
8 | #define DEFAULT_WIDTH 800
9 | #define DEFAULT_HEIGHT 600
10 | #define DEFAULT_BPP 24
11 |
12 | /* ============================= Data structures ============================ */
13 |
14 | struct globalConfig {
15 | /* Runtime */
16 | int r,g,b;
17 | int alpha;
18 | int fps;
19 | long long start_ms;
20 | long long epoch;
21 | frameBuffer *fb;
22 | char *filename;
23 | lua_State *L;
24 | int luaerr; /* True if there was an error in the latest iteration. */
25 | /* Configuration */
26 | int width;
27 | int height;
28 | int bpp;
29 | /* Command line switches */
30 | int opt_show_fps;
31 | int opt_full_screen;
32 | };
33 |
34 | extern struct globalConfig l81;
35 |
36 | #endif /* LOAD81_H */
37 |
--------------------------------------------------------------------------------
/lua/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 |
--------------------------------------------------------------------------------
/lua/INSTALL:
--------------------------------------------------------------------------------
1 | INSTALL for Lua 5.1
2 |
3 | * Building Lua
4 | ------------
5 | Lua is built in the src directory, but the build process can be
6 | controlled from the top-level Makefile.
7 |
8 | Building Lua on Unix systems should be very easy. First do "make" and
9 | see if your platform is listed. If so, just do "make xxx", where xxx
10 | is your platform name. The platforms currently supported are:
11 | aix ansi bsd freebsd generic linux macosx mingw posix solaris
12 |
13 | If your platform is not listed, try the closest one or posix, generic,
14 | ansi, in this order.
15 |
16 | See below for customization instructions and for instructions on how
17 | to build with other Windows compilers.
18 |
19 | If you want to check that Lua has been built correctly, do "make test"
20 | after building Lua. Also, have a look at the example programs in test.
21 |
22 | * Installing Lua
23 | --------------
24 | Once you have built Lua, you may want to install it in an official
25 | place in your system. In this case, do "make install". The official
26 | place and the way to install files are defined in Makefile. You must
27 | have the right permissions to install files.
28 |
29 | If you want to build and install Lua in one step, do "make xxx install",
30 | where xxx is your platform name.
31 |
32 | If you want to install Lua locally, then do "make local". This will
33 | create directories bin, include, lib, man, and install Lua there as
34 | follows:
35 |
36 | bin: lua luac
37 | include: lua.h luaconf.h lualib.h lauxlib.h lua.hpp
38 | lib: liblua.a
39 | man/man1: lua.1 luac.1
40 |
41 | These are the only directories you need for development.
42 |
43 | There are man pages for lua and luac, in both nroff and html, and a
44 | reference manual in html in doc, some sample code in test, and some
45 | useful stuff in etc. You don't need these directories for development.
46 |
47 | If you want to install Lua locally, but in some other directory, do
48 | "make install INSTALL_TOP=xxx", where xxx is your chosen directory.
49 |
50 | See below for instructions for Windows and other systems.
51 |
52 | * Customization
53 | -------------
54 | Three things can be customized by editing a file:
55 | - Where and how to install Lua -- edit Makefile.
56 | - How to build Lua -- edit src/Makefile.
57 | - Lua features -- edit src/luaconf.h.
58 |
59 | You don't actually need to edit the Makefiles because you may set the
60 | relevant variables when invoking make.
61 |
62 | On the other hand, if you need to select some Lua features, you'll need
63 | to edit src/luaconf.h. The edited file will be the one installed, and
64 | it will be used by any Lua clients that you build, to ensure consistency.
65 |
66 | We strongly recommend that you enable dynamic loading. This is done
67 | automatically for all platforms listed above that have this feature
68 | (and also Windows). See src/luaconf.h and also src/Makefile.
69 |
70 | * Building Lua on Windows and other systems
71 | -----------------------------------------
72 | If you're not using the usual Unix tools, then the instructions for
73 | building Lua depend on the compiler you use. You'll need to create
74 | projects (or whatever your compiler uses) for building the library,
75 | the interpreter, and the compiler, as follows:
76 |
77 | library: lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
78 | lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c
79 | ltable.c ltm.c lundump.c lvm.c lzio.c
80 | lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c
81 | ltablib.c lstrlib.c loadlib.c linit.c
82 |
83 | interpreter: library, lua.c
84 |
85 | compiler: library, luac.c print.c
86 |
87 | If you use Visual Studio .NET, you can use etc/luavs.bat in its
88 | "Command Prompt".
89 |
90 | If all you want is to build the Lua interpreter, you may put all .c files
91 | in a single project, except for luac.c and print.c. Or just use etc/all.c.
92 |
93 | To use Lua as a library in your own programs, you'll need to know how to
94 | create and use libraries with your compiler.
95 |
96 | As mentioned above, you may edit luaconf.h to select some features before
97 | building Lua.
98 |
99 | (end of INSTALL)
100 |
--------------------------------------------------------------------------------
/lua/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 |
--------------------------------------------------------------------------------
/lua/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 |
--------------------------------------------------------------------------------
/lua/doc/cover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antirez/load81/f3b4404c2ba9fe24dcad3fdc8679de9662fcc1f5/lua/doc/cover.png
--------------------------------------------------------------------------------
/lua/doc/logo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/antirez/load81/f3b4404c2ba9fe24dcad3fdc8679de9662fcc1f5/lua/doc/logo.gif
--------------------------------------------------------------------------------
/lua/doc/lua.1:
--------------------------------------------------------------------------------
1 | .\" $Id: lua.man,v 1.11 2006/01/06 16:03:34 lhf Exp $
2 | .TH LUA 1 "$Date: 2006/01/06 16:03:34 $"
3 | .SH NAME
4 | lua \- Lua interpreter
5 | .SH SYNOPSIS
6 | .B lua
7 | [
8 | .I options
9 | ]
10 | [
11 | .I script
12 | [
13 | .I args
14 | ]
15 | ]
16 | .SH DESCRIPTION
17 | .B lua
18 | is the stand-alone Lua interpreter.
19 | It loads and executes Lua programs,
20 | either in textual source form or
21 | in precompiled binary form.
22 | (Precompiled binaries are output by
23 | .BR luac ,
24 | the Lua compiler.)
25 | .B lua
26 | can be used as a batch interpreter and also interactively.
27 | .LP
28 | The given
29 | .I options
30 | (see below)
31 | are executed and then
32 | the Lua program in file
33 | .I script
34 | is loaded and executed.
35 | The given
36 | .I args
37 | are available to
38 | .I script
39 | as strings in a global table named
40 | .BR arg .
41 | If these arguments contain spaces or other characters special to the shell,
42 | then they should be quoted
43 | (but note that the quotes will be removed by the shell).
44 | The arguments in
45 | .B arg
46 | start at 0,
47 | which contains the string
48 | .RI ' script '.
49 | The index of the last argument is stored in
50 | .BR arg.n .
51 | The arguments given in the command line before
52 | .IR script ,
53 | including the name of the interpreter,
54 | are available in negative indices in
55 | .BR arg .
56 | .LP
57 | At the very start,
58 | before even handling the command line,
59 | .B lua
60 | executes the contents of the environment variable
61 | .BR LUA_INIT ,
62 | if it is defined.
63 | If the value of
64 | .B LUA_INIT
65 | is of the form
66 | .RI '@ filename ',
67 | then
68 | .I filename
69 | is executed.
70 | Otherwise, the string is assumed to be a Lua statement and is executed.
71 | .LP
72 | Options start with
73 | .B '\-'
74 | and are described below.
75 | You can use
76 | .B "'\--'"
77 | to signal the end of options.
78 | .LP
79 | If no arguments are given,
80 | then
81 | .B "\-v \-i"
82 | is assumed when the standard input is a terminal;
83 | otherwise,
84 | .B "\-"
85 | is assumed.
86 | .LP
87 | In interactive mode,
88 | .B lua
89 | prompts the user,
90 | reads lines from the standard input,
91 | and executes them as they are read.
92 | If a line does not contain a complete statement,
93 | then a secondary prompt is displayed and
94 | lines are read until a complete statement is formed or
95 | a syntax error is found.
96 | So, one way to interrupt the reading of an incomplete statement is
97 | to force a syntax error:
98 | adding a
99 | .B ';'
100 | in the middle of a statement is a sure way of forcing a syntax error
101 | (except inside multiline strings and comments; these must be closed explicitly).
102 | If a line starts with
103 | .BR '=' ,
104 | then
105 | .B lua
106 | displays the values of all the expressions in the remainder of the
107 | line. The expressions must be separated by commas.
108 | The primary prompt is the value of the global variable
109 | .BR _PROMPT ,
110 | if this value is a string;
111 | otherwise, the default prompt is used.
112 | Similarly, the secondary prompt is the value of the global variable
113 | .BR _PROMPT2 .
114 | So,
115 | to change the prompts,
116 | set the corresponding variable to a string of your choice.
117 | You can do that after calling the interpreter
118 | or on the command line
119 | (but in this case you have to be careful with quotes
120 | if the prompt string contains a space; otherwise you may confuse the shell.)
121 | The default prompts are "> " and ">> ".
122 | .SH OPTIONS
123 | .TP
124 | .B \-
125 | load and execute the standard input as a file,
126 | that is,
127 | not interactively,
128 | even when the standard input is a terminal.
129 | .TP
130 | .BI \-e " stat"
131 | execute statement
132 | .IR stat .
133 | You need to quote
134 | .I stat
135 | if it contains spaces, quotes,
136 | or other characters special to the shell.
137 | .TP
138 | .B \-i
139 | enter interactive mode after
140 | .I script
141 | is executed.
142 | .TP
143 | .BI \-l " name"
144 | call
145 | .BI require(' name ')
146 | before executing
147 | .IR script .
148 | Typically used to load libraries.
149 | .TP
150 | .B \-v
151 | show version information.
152 | .SH "SEE ALSO"
153 | .BR luac (1)
154 | .br
155 | http://www.lua.org/
156 | .SH DIAGNOSTICS
157 | Error messages should be self explanatory.
158 | .SH AUTHORS
159 | R. Ierusalimschy,
160 | L. H. de Figueiredo,
161 | and
162 | W. Celes
163 | .\" EOF
164 |
--------------------------------------------------------------------------------
/lua/doc/lua.css:
--------------------------------------------------------------------------------
1 | body {
2 | color: #000000 ;
3 | background-color: #FFFFFF ;
4 | font-family: Helvetica, Arial, sans-serif ;
5 | text-align: justify ;
6 | margin-right: 30px ;
7 | margin-left: 30px ;
8 | }
9 |
10 | h1, h2, h3, h4 {
11 | font-family: Verdana, Geneva, sans-serif ;
12 | font-weight: normal ;
13 | font-style: italic ;
14 | }
15 |
16 | h2 {
17 | padding-top: 0.4em ;
18 | padding-bottom: 0.4em ;
19 | padding-left: 30px ;
20 | padding-right: 30px ;
21 | margin-left: -30px ;
22 | background-color: #E0E0FF ;
23 | }
24 |
25 | h3 {
26 | padding-left: 0.5em ;
27 | border-left: solid #E0E0FF 1em ;
28 | }
29 |
30 | table h3 {
31 | padding-left: 0px ;
32 | border-left: none ;
33 | }
34 |
35 | a:link {
36 | color: #000080 ;
37 | background-color: inherit ;
38 | text-decoration: none ;
39 | }
40 |
41 | a:visited {
42 | background-color: inherit ;
43 | text-decoration: none ;
44 | }
45 |
46 | a:link:hover, a:visited:hover {
47 | color: #000080 ;
48 | background-color: #E0E0FF ;
49 | }
50 |
51 | a:link:active, a:visited:active {
52 | color: #FF0000 ;
53 | }
54 |
55 | hr {
56 | border: 0 ;
57 | height: 1px ;
58 | color: #a0a0a0 ;
59 | background-color: #a0a0a0 ;
60 | }
61 |
62 | :target {
63 | background-color: #F8F8F8 ;
64 | padding: 8px ;
65 | border: solid #a0a0a0 2px ;
66 | }
67 |
68 | .footer {
69 | color: gray ;
70 | font-size: small ;
71 | }
72 |
73 | input[type=text] {
74 | border: solid #a0a0a0 2px ;
75 | border-radius: 2em ;
76 | -moz-border-radius: 2em ;
77 | background-image: url('images/search.png') ;
78 | background-repeat: no-repeat;
79 | background-position: 4px center ;
80 | padding-left: 20px ;
81 | height: 2em ;
82 | }
83 |
84 |
--------------------------------------------------------------------------------
/lua/doc/lua.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | LUA man page
5 |
6 |
7 |
8 |
9 |
10 |
24 | lua
25 | is the stand-alone Lua interpreter.
26 | It loads and executes Lua programs,
27 | either in textual source form or
28 | in precompiled binary form.
29 | (Precompiled binaries are output by
30 | luac,
31 | the Lua compiler.)
32 | lua
33 | can be used as a batch interpreter and also interactively.
34 |
35 | The given
36 | options
37 | (see below)
38 | are executed and then
39 | the Lua program in file
40 | script
41 | is loaded and executed.
42 | The given
43 | args
44 | are available to
45 | script
46 | as strings in a global table named
47 | arg.
48 | If these arguments contain spaces or other characters special to the shell,
49 | then they should be quoted
50 | (but note that the quotes will be removed by the shell).
51 | The arguments in
52 | arg
53 | start at 0,
54 | which contains the string
55 | 'script'.
56 | The index of the last argument is stored in
57 | arg.n.
58 | The arguments given in the command line before
59 | script,
60 | including the name of the interpreter,
61 | are available in negative indices in
62 | arg.
63 |
64 | At the very start,
65 | before even handling the command line,
66 | lua
67 | executes the contents of the environment variable
68 | LUA_INIT,
69 | if it is defined.
70 | If the value of
71 | LUA_INIT
72 | is of the form
73 | '@filename',
74 | then
75 | filename
76 | is executed.
77 | Otherwise, the string is assumed to be a Lua statement and is executed.
78 |
79 | Options start with
80 | '-'
81 | and are described below.
82 | You can use
83 | '--'
84 | to signal the end of options.
85 |
86 | If no arguments are given,
87 | then
88 | "-v -i"
89 | is assumed when the standard input is a terminal;
90 | otherwise,
91 | "-"
92 | is assumed.
93 |
94 | In interactive mode,
95 | lua
96 | prompts the user,
97 | reads lines from the standard input,
98 | and executes them as they are read.
99 | If a line does not contain a complete statement,
100 | then a secondary prompt is displayed and
101 | lines are read until a complete statement is formed or
102 | a syntax error is found.
103 | So, one way to interrupt the reading of an incomplete statement is
104 | to force a syntax error:
105 | adding a
106 | ';'
107 | in the middle of a statement is a sure way of forcing a syntax error
108 | (except inside multiline strings and comments; these must be closed explicitly).
109 | If a line starts with
110 | '=',
111 | then
112 | lua
113 | displays the values of all the expressions in the remainder of the
114 | line. The expressions must be separated by commas.
115 | The primary prompt is the value of the global variable
116 | _PROMPT,
117 | if this value is a string;
118 | otherwise, the default prompt is used.
119 | Similarly, the secondary prompt is the value of the global variable
120 | _PROMPT2.
121 | So,
122 | to change the prompts,
123 | set the corresponding variable to a string of your choice.
124 | You can do that after calling the interpreter
125 | or on the command line
126 | (but in this case you have to be careful with quotes
127 | if the prompt string contains a space; otherwise you may confuse the shell.)
128 | The default prompts are "> " and ">> ".
129 |
OPTIONS
130 |
131 | -
132 | load and execute the standard input as a file,
133 | that is,
134 | not interactively,
135 | even when the standard input is a terminal.
136 |
137 | -e stat
138 | execute statement
139 | stat.
140 | You need to quote
141 | stat
142 | if it contains spaces, quotes,
143 | or other characters special to the shell.
144 |
145 | -i
146 | enter interactive mode after
147 | script
148 | is executed.
149 |
150 | -l name
151 | call
152 | require('name')
153 | before executing
154 | script.
155 | Typically used to load libraries.
156 |
164 | Error messages should be self explanatory.
165 |
AUTHORS
166 | R. Ierusalimschy,
167 | L. H. de Figueiredo,
168 | and
169 | W. Celes
170 |
171 |
172 |
173 |
--------------------------------------------------------------------------------
/lua/doc/luac.1:
--------------------------------------------------------------------------------
1 | .\" $Id: luac.man,v 1.28 2006/01/06 16:03:34 lhf Exp $
2 | .TH LUAC 1 "$Date: 2006/01/06 16:03:34 $"
3 | .SH NAME
4 | luac \- Lua compiler
5 | .SH SYNOPSIS
6 | .B luac
7 | [
8 | .I options
9 | ] [
10 | .I filenames
11 | ]
12 | .SH DESCRIPTION
13 | .B luac
14 | is the Lua compiler.
15 | It translates programs written in the Lua programming language
16 | into binary files that can be later loaded and executed.
17 | .LP
18 | The main advantages of precompiling chunks are:
19 | faster loading,
20 | protecting source code from accidental user changes,
21 | and
22 | off-line syntax checking.
23 | .LP
24 | Pre-compiling does not imply faster execution
25 | because in Lua chunks are always compiled into bytecodes before being executed.
26 | .B luac
27 | simply allows those bytecodes to be saved in a file for later execution.
28 | .LP
29 | Pre-compiled chunks are not necessarily smaller than the corresponding source.
30 | The main goal in pre-compiling is faster loading.
31 | .LP
32 | The binary files created by
33 | .B luac
34 | are portable only among architectures with the same word size and byte order.
35 | .LP
36 | .B luac
37 | produces a single output file containing the bytecodes
38 | for all source files given.
39 | By default,
40 | the output file is named
41 | .BR luac.out ,
42 | but you can change this with the
43 | .B \-o
44 | option.
45 | .LP
46 | In the command line,
47 | you can mix
48 | text files containing Lua source and
49 | binary files containing precompiled chunks.
50 | This is useful to combine several precompiled chunks,
51 | even from different (but compatible) platforms,
52 | into a single precompiled chunk.
53 | .LP
54 | You can use
55 | .B "'\-'"
56 | to indicate the standard input as a source file
57 | and
58 | .B "'\--'"
59 | to signal the end of options
60 | (that is,
61 | all remaining arguments will be treated as files even if they start with
62 | .BR "'\-'" ).
63 | .LP
64 | The internal format of the binary files produced by
65 | .B luac
66 | is likely to change when a new version of Lua is released.
67 | So,
68 | save the source files of all Lua programs that you precompile.
69 | .LP
70 | .SH OPTIONS
71 | Options must be separate.
72 | .TP
73 | .B \-l
74 | produce a listing of the compiled bytecode for Lua's virtual machine.
75 | Listing bytecodes is useful to learn about Lua's virtual machine.
76 | If no files are given, then
77 | .B luac
78 | loads
79 | .B luac.out
80 | and lists its contents.
81 | .TP
82 | .BI \-o " file"
83 | output to
84 | .IR file ,
85 | instead of the default
86 | .BR luac.out .
87 | (You can use
88 | .B "'\-'"
89 | for standard output,
90 | but not on platforms that open standard output in text mode.)
91 | The output file may be a source file because
92 | all files are loaded before the output file is written.
93 | Be careful not to overwrite precious files.
94 | .TP
95 | .B \-p
96 | load files but do not generate any output file.
97 | Used mainly for syntax checking and for testing precompiled chunks:
98 | corrupted files will probably generate errors when loaded.
99 | Lua always performs a thorough integrity test on precompiled chunks.
100 | Bytecode that passes this test is completely safe,
101 | in the sense that it will not break the interpreter.
102 | However,
103 | there is no guarantee that such code does anything sensible.
104 | (None can be given, because the halting problem is unsolvable.)
105 | If no files are given, then
106 | .B luac
107 | loads
108 | .B luac.out
109 | and tests its contents.
110 | No messages are displayed if the file passes the integrity test.
111 | .TP
112 | .B \-s
113 | strip debug information before writing the output file.
114 | This saves some space in very large chunks,
115 | but if errors occur when running a stripped chunk,
116 | then the error messages may not contain the full information they usually do.
117 | For instance,
118 | line numbers and names of local variables are lost.
119 | .TP
120 | .B \-v
121 | show version information.
122 | .SH FILES
123 | .TP 15
124 | .B luac.out
125 | default output file
126 | .SH "SEE ALSO"
127 | .BR lua (1)
128 | .br
129 | http://www.lua.org/
130 | .SH DIAGNOSTICS
131 | Error messages should be self explanatory.
132 | .SH AUTHORS
133 | L. H. de Figueiredo,
134 | R. Ierusalimschy and
135 | W. Celes
136 | .\" EOF
137 |
--------------------------------------------------------------------------------
/lua/doc/luac.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | LUAC man page
5 |
6 |
7 |
8 |
9 |
10 |
20 | luac
21 | is the Lua compiler.
22 | It translates programs written in the Lua programming language
23 | into binary files that can be later loaded and executed.
24 |
25 | The main advantages of precompiling chunks are:
26 | faster loading,
27 | protecting source code from accidental user changes,
28 | and
29 | off-line syntax checking.
30 |
31 | Precompiling does not imply faster execution
32 | because in Lua chunks are always compiled into bytecodes before being executed.
33 | luac
34 | simply allows those bytecodes to be saved in a file for later execution.
35 |
36 | Precompiled chunks are not necessarily smaller than the corresponding source.
37 | The main goal in precompiling is faster loading.
38 |
39 | The binary files created by
40 | luac
41 | are portable only among architectures with the same word size and byte order.
42 |
43 | luac
44 | produces a single output file containing the bytecodes
45 | for all source files given.
46 | By default,
47 | the output file is named
48 | luac.out,
49 | but you can change this with the
50 | -o
51 | option.
52 |
53 | In the command line,
54 | you can mix
55 | text files containing Lua source and
56 | binary files containing precompiled chunks.
57 | This is useful because several precompiled chunks,
58 | even from different (but compatible) platforms,
59 | can be combined into a single precompiled chunk.
60 |
61 | You can use
62 | '-'
63 | to indicate the standard input as a source file
64 | and
65 | '--'
66 | to signal the end of options
67 | (that is,
68 | all remaining arguments will be treated as files even if they start with
69 | '-').
70 |
71 | The internal format of the binary files produced by
72 | luac
73 | is likely to change when a new version of Lua is released.
74 | So,
75 | save the source files of all Lua programs that you precompile.
76 |
77 |
OPTIONS
78 | Options must be separate.
79 |
80 | -l
81 | produce a listing of the compiled bytecode for Lua's virtual machine.
82 | Listing bytecodes is useful to learn about Lua's virtual machine.
83 | If no files are given, then
84 | luac
85 | loads
86 | luac.out
87 | and lists its contents.
88 |
89 | -o file
90 | output to
91 | file,
92 | instead of the default
93 | luac.out.
94 | (You can use
95 | '-'
96 | for standard output,
97 | but not on platforms that open standard output in text mode.)
98 | The output file may be a source file because
99 | all files are loaded before the output file is written.
100 | Be careful not to overwrite precious files.
101 |
102 | -p
103 | load files but do not generate any output file.
104 | Used mainly for syntax checking and for testing precompiled chunks:
105 | corrupted files will probably generate errors when loaded.
106 | Lua always performs a thorough integrity test on precompiled chunks.
107 | Bytecode that passes this test is completely safe,
108 | in the sense that it will not break the interpreter.
109 | However,
110 | there is no guarantee that such code does anything sensible.
111 | (None can be given, because the halting problem is unsolvable.)
112 | If no files are given, then
113 | luac
114 | loads
115 | luac.out
116 | and tests its contents.
117 | No messages are displayed if the file passes the integrity test.
118 |
119 | -s
120 | strip debug information before writing the output file.
121 | This saves some space in very large chunks,
122 | but if errors occur when running a stripped chunk,
123 | then the error messages may not contain the full information they usually do.
124 | For instance,
125 | line numbers and names of local variables are lost.
126 |