aboutsummaryrefslogtreecommitdiff
path: root/libs/lua/etc
diff options
context:
space:
mode:
authorPavel Labath <pavelo@centrum.sk>2011-05-16 10:58:21 (GMT)
committerPaul Tagliamonte <paultag@fluxbox.org>2012-04-07 02:08:41 (GMT)
commit0fa62fe1598c5b04925c0b7b98d0d00d28d10d88 (patch)
treeccc2dd040a03b294b17abaa4da55ca00ed9b82a7 /libs/lua/etc
parent7b6dc2ad72a4c4ecd20eddbfb6f1b4c3bd2a7024 (diff)
downloadfluxbox_paul-0fa62fe1598c5b04925c0b7b98d0d00d28d10d88.zip
fluxbox_paul-0fa62fe1598c5b04925c0b7b98d0d00d28d10d88.tar.bz2
Add lua as an internal library in libs/lua
Diffstat (limited to 'libs/lua/etc')
-rw-r--r--libs/lua/etc/README37
-rw-r--r--libs/lua/etc/all.c38
-rw-r--r--libs/lua/etc/lua.hpp9
-rw-r--r--libs/lua/etc/lua.icobin0 -> 1078 bytes
-rw-r--r--libs/lua/etc/lua.pc31
-rw-r--r--libs/lua/etc/luavs.bat28
-rw-r--r--libs/lua/etc/min.c39
-rw-r--r--libs/lua/etc/noparser.c50
-rw-r--r--libs/lua/etc/strict.lua41
9 files changed, 273 insertions, 0 deletions
diff --git a/libs/lua/etc/README b/libs/lua/etc/README
new file mode 100644
index 0000000..5149fc9
--- /dev/null
+++ b/libs/lua/etc/README
@@ -0,0 +1,37 @@
1This directory contains some useful files and code.
2Unlike the code in ../src, everything here is in the public domain.
3
4If any of the makes fail, you're probably not using the same libraries
5used to build Lua. Set MYLIBS in Makefile accordingly.
6
7all.c
8 Full Lua interpreter in a single file.
9 Do "make one" for a demo.
10
11lua.hpp
12 Lua header files for C++ using 'extern "C"'.
13
14lua.ico
15 A Lua icon for Windows (and web sites: save as favicon.ico).
16 Drawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>.
17
18lua.pc
19 pkg-config data for Lua
20
21luavs.bat
22 Script to build Lua under "Visual Studio .NET Command Prompt".
23 Run it from the toplevel as etc\luavs.bat.
24
25min.c
26 A minimal Lua interpreter.
27 Good for learning and for starting your own.
28 Do "make min" for a demo.
29
30noparser.c
31 Linking with noparser.o avoids loading the parsing modules in lualib.a.
32 Do "make noparser" for a demo.
33
34strict.lua
35 Traps uses of undeclared global variables.
36 Do "make strict" for a demo.
37
diff --git a/libs/lua/etc/all.c b/libs/lua/etc/all.c
new file mode 100644
index 0000000..dab68fa
--- /dev/null
+++ b/libs/lua/etc/all.c
@@ -0,0 +1,38 @@
1/*
2* all.c -- Lua core, libraries and interpreter in a single file
3*/
4
5#define luaall_c
6
7#include "lapi.c"
8#include "lcode.c"
9#include "ldebug.c"
10#include "ldo.c"
11#include "ldump.c"
12#include "lfunc.c"
13#include "lgc.c"
14#include "llex.c"
15#include "lmem.c"
16#include "lobject.c"
17#include "lopcodes.c"
18#include "lparser.c"
19#include "lstate.c"
20#include "lstring.c"
21#include "ltable.c"
22#include "ltm.c"
23#include "lundump.c"
24#include "lvm.c"
25#include "lzio.c"
26
27#include "lauxlib.c"
28#include "lbaselib.c"
29#include "ldblib.c"
30#include "liolib.c"
31#include "linit.c"
32#include "lmathlib.c"
33#include "loadlib.c"
34#include "loslib.c"
35#include "lstrlib.c"
36#include "ltablib.c"
37
38#include "lua.c"
diff --git a/libs/lua/etc/lua.hpp b/libs/lua/etc/lua.hpp
new file mode 100644
index 0000000..ec417f5
--- /dev/null
+++ b/libs/lua/etc/lua.hpp
@@ -0,0 +1,9 @@
1// lua.hpp
2// Lua header files for C++
3// <<extern "C">> not supplied automatically because Lua also compiles as C++
4
5extern "C" {
6#include "lua.h"
7#include "lualib.h"
8#include "lauxlib.h"
9}
diff --git a/libs/lua/etc/lua.ico b/libs/lua/etc/lua.ico
new file mode 100644
index 0000000..ccbabc4
--- /dev/null
+++ b/libs/lua/etc/lua.ico
Binary files differ
diff --git a/libs/lua/etc/lua.pc b/libs/lua/etc/lua.pc
new file mode 100644
index 0000000..f52f55b
--- /dev/null
+++ b/libs/lua/etc/lua.pc
@@ -0,0 +1,31 @@
1# lua.pc -- pkg-config data for Lua
2
3# vars from install Makefile
4
5# grep '^V=' ../Makefile
6V= 5.1
7# grep '^R=' ../Makefile
8R= 5.1.4
9
10# grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/'
11prefix= /usr/local
12INSTALL_BIN= ${prefix}/bin
13INSTALL_INC= ${prefix}/include
14INSTALL_LIB= ${prefix}/lib
15INSTALL_MAN= ${prefix}/man/man1
16INSTALL_LMOD= ${prefix}/share/lua/${V}
17INSTALL_CMOD= ${prefix}/lib/lua/${V}
18
19# canonical vars
20exec_prefix=${prefix}
21libdir=${exec_prefix}/lib
22includedir=${prefix}/include
23
24Name: Lua
25Description: An Extensible Extension Language
26Version: ${R}
27Requires:
28Libs: -L${libdir} -llua -lm
29Cflags: -I${includedir}
30
31# (end of lua.pc)
diff --git a/libs/lua/etc/luavs.bat b/libs/lua/etc/luavs.bat
new file mode 100644
index 0000000..08c2bed
--- /dev/null
+++ b/libs/lua/etc/luavs.bat
@@ -0,0 +1,28 @@
1@rem Script to build Lua under "Visual Studio .NET Command Prompt".
2@rem Do not run from this directory; run it from the toplevel: etc\luavs.bat .
3@rem It creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src.
4@rem (contributed by David Manura and Mike Pall)
5
6@setlocal
7@set MYCOMPILE=cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
8@set MYLINK=link /nologo
9@set MYMT=mt /nologo
10
11cd src
12%MYCOMPILE% /DLUA_BUILD_AS_DLL l*.c
13del lua.obj luac.obj
14%MYLINK% /DLL /out:lua51.dll l*.obj
15if exist lua51.dll.manifest^
16 %MYMT% -manifest lua51.dll.manifest -outputresource:lua51.dll;2
17%MYCOMPILE% /DLUA_BUILD_AS_DLL lua.c
18%MYLINK% /out:lua.exe lua.obj lua51.lib
19if exist lua.exe.manifest^
20 %MYMT% -manifest lua.exe.manifest -outputresource:lua.exe
21%MYCOMPILE% l*.c print.c
22del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj^
23 loslib.obj ltablib.obj lstrlib.obj loadlib.obj
24%MYLINK% /out:luac.exe *.obj
25if exist luac.exe.manifest^
26 %MYMT% -manifest luac.exe.manifest -outputresource:luac.exe
27del *.obj *.manifest
28cd ..
diff --git a/libs/lua/etc/min.c b/libs/lua/etc/min.c
new file mode 100644
index 0000000..6a85a4d
--- /dev/null
+++ b/libs/lua/etc/min.c
@@ -0,0 +1,39 @@
1/*
2* min.c -- a minimal Lua interpreter
3* loads stdin only with minimal error handling.
4* no interaction, and no standard library, only a "print" function.
5*/
6
7#include <stdio.h>
8
9#include "lua.h"
10#include "lauxlib.h"
11
12static int print(lua_State *L)
13{
14 int n=lua_gettop(L);
15 int i;
16 for (i=1; i<=n; i++)
17 {
18 if (i>1) printf("\t");
19 if (lua_isstring(L,i))
20 printf("%s",lua_tostring(L,i));
21 else if (lua_isnil(L,i))
22 printf("%s","nil");
23 else if (lua_isboolean(L,i))
24 printf("%s",lua_toboolean(L,i) ? "true" : "false");
25 else
26 printf("%s:%p",luaL_typename(L,i),lua_topointer(L,i));
27 }
28 printf("\n");
29 return 0;
30}
31
32int main(void)
33{
34 lua_State *L=lua_open();
35 lua_register(L,"print",print);
36 if (luaL_dofile(L,NULL)!=0) fprintf(stderr,"%s\n",lua_tostring(L,-1));
37 lua_close(L);
38 return 0;
39}
diff --git a/libs/lua/etc/noparser.c b/libs/lua/etc/noparser.c
new file mode 100644
index 0000000..13ba546
--- /dev/null
+++ b/libs/lua/etc/noparser.c
@@ -0,0 +1,50 @@
1/*
2* The code below can be used to make a Lua core that does not contain the
3* parsing modules (lcode, llex, lparser), which represent 35% of the total core.
4* You'll only be able to load binary files and strings, precompiled with luac.
5* (Of course, you'll have to build luac with the original parsing modules!)
6*
7* To use this module, simply compile it ("make noparser" does that) and list
8* its object file before the Lua libraries. The linker should then not load
9* the parsing modules. To try it, do "make luab".
10*
11* If you also want to avoid the dump module (ldump.o), define NODUMP.
12* #define NODUMP
13*/
14
15#define LUA_CORE
16
17#include "llex.h"
18#include "lparser.h"
19#include "lzio.h"
20
21LUAI_FUNC void luaX_init (lua_State *L) {
22 UNUSED(L);
23}
24
25LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
26 UNUSED(z);
27 UNUSED(buff);
28 UNUSED(name);
29 lua_pushliteral(L,"parser not loaded");
30 lua_error(L);
31 return NULL;
32}
33
34#ifdef NODUMP
35#include "lundump.h"
36
37LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) {
38 UNUSED(f);
39 UNUSED(w);
40 UNUSED(data);
41 UNUSED(strip);
42#if 1
43 UNUSED(L);
44 return 0;
45#else
46 lua_pushliteral(L,"dumper not loaded");
47 lua_error(L);
48#endif
49}
50#endif
diff --git a/libs/lua/etc/strict.lua b/libs/lua/etc/strict.lua
new file mode 100644
index 0000000..604619d
--- /dev/null
+++ b/libs/lua/etc/strict.lua
@@ -0,0 +1,41 @@
1--
2-- strict.lua
3-- checks uses of undeclared global variables
4-- All global variables must be 'declared' through a regular assignment
5-- (even assigning nil will do) in a main chunk before being used
6-- anywhere or assigned to inside a function.
7--
8
9local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget
10
11local mt = getmetatable(_G)
12if mt == nil then
13 mt = {}
14 setmetatable(_G, mt)
15end
16
17mt.__declared = {}
18
19local function what ()
20 local d = getinfo(3, "S")
21 return d and d.what or "C"
22end
23
24mt.__newindex = function (t, n, v)
25 if not mt.__declared[n] then
26 local w = what()
27 if w ~= "main" and w ~= "C" then
28 error("assign to undeclared variable '"..n.."'", 2)
29 end
30 mt.__declared[n] = true
31 end
32 rawset(t, n, v)
33end
34
35mt.__index = function (t, n)
36 if not mt.__declared[n] and what() ~= "C" then
37 error("variable '"..n.."' is not declared", 2)
38 end
39 return rawget(t, n)
40end
41