summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
Diffstat (limited to 'etc')
-rw-r--r--etc/Makefile11
-rw-r--r--etc/README14
-rw-r--r--etc/luavs.bat7
-rw-r--r--etc/noparser.c22
-rw-r--r--etc/strict.lua34
5 files changed, 71 insertions, 17 deletions
diff --git a/etc/Makefile b/etc/Makefile
index fc3d1468..2dfc937c 100644
--- a/etc/Makefile
+++ b/etc/Makefile
@@ -14,13 +14,12 @@ MYLDFLAGS= -Wl,-E
MYLIBS= -lm -ldl
RM= rm -f
-ALL= min noparser.o 1
-
all:
- @echo 'choose a target:' $(ALL)
+ @echo 'choose a target: min noparser one clean'
min: min.c
- $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua $(MYLIBS)
+ $(CC) $(CFLAGS) $@.c -L$(LIB) -llua $(MYLIBS)
+ echo 'print"Hello there!"' | ./a.out
noparser: noparser.o
$(CC) noparser.o $(SRC)/lua.o -L$(LIB) -llua $(MYLIBS)
@@ -28,9 +27,9 @@ noparser: noparser.o
-./a.out luac.out
-./a.out -e'a=1'
-1:
+one:
$(CC) $(CFLAGS) all.c $(MYLIBS)
./a.out $(TST)/hello.lua
clean:
- $(RM) $(ALL) a.out core core.* *.o luac.out
+ $(RM) noparser.o a.out core core.* *.o luac.out
diff --git a/etc/README b/etc/README
index 47626769..5e42ec56 100644
--- a/etc/README
+++ b/etc/README
@@ -3,19 +3,21 @@ Unlike the code in ../src, everything here is in the public domain.
all.c
Full Lua interpreter in a single file.
- Do "make 1".
+ Do "make one".
lua.hpp
- Lua header files for C++.
- This keeps the C interface to Lua. But Lua also compiles as clean C++.
+ Lua header files for C++ using 'extern "C"'.
lua.ico
- A Lua icon for Windows (and web sites, as favicon.ico).
+ A Lua icon for Windows (and web sites: save as favicon.ico).
Drawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>.
lua.pc
pkg-config data for Lua
+luavs.bat
+ Script to build Lua under "Visual Studio .NET Command Prompt".
+
min.c
A minimal Lua interpreter.
Good for learning and for starting your own.
@@ -23,3 +25,7 @@ min.c
noparser.c
Linking with noparser.o avoids loading the parsing modules in lualib.a.
Do "make noparser" to see a demo.
+
+strict.lua
+ Traps uses of undeclared global variables.
+
diff --git a/etc/luavs.bat b/etc/luavs.bat
new file mode 100644
index 00000000..eea175e3
--- /dev/null
+++ b/etc/luavs.bat
@@ -0,0 +1,7 @@
+cd src
+cl /O2 /W3 /c /DLUA_BUILD_AS_DLL l*.c
+del lua.obj luac.obj
+link /DLL /out:lua51.dll l*.obj
+cl /O2 /W3 /c /DLUA_BUILD_AS_DLL lua.c
+link /out:lua.exe lua.obj lua51.lib
+cd ..
diff --git a/etc/noparser.c b/etc/noparser.c
index 9396ad60..13ba5462 100644
--- a/etc/noparser.c
+++ b/etc/noparser.c
@@ -18,13 +18,14 @@
#include "lparser.h"
#include "lzio.h"
-void luaX_init (lua_State *L) {
+LUAI_FUNC void luaX_init (lua_State *L) {
UNUSED(L);
}
-Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
+LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
UNUSED(z);
UNUSED(buff);
+ UNUSED(name);
lua_pushliteral(L,"parser not loaded");
lua_error(L);
return NULL;
@@ -33,10 +34,17 @@ Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
#ifdef NODUMP
#include "lundump.h"
-int luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data, int strip)
-{
- return 0;
- lua_pushliteral(L,"dumper not loaded");
- lua_error(L);
+LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip) {
+ UNUSED(f);
+ UNUSED(w);
+ UNUSED(data);
+ UNUSED(strip);
+#if 1
+ UNUSED(L);
+ return 0;
+#else
+ lua_pushliteral(L,"dumper not loaded");
+ lua_error(L);
+#endif
}
#endif
diff --git a/etc/strict.lua b/etc/strict.lua
new file mode 100644
index 00000000..7c9fa159
--- /dev/null
+++ b/etc/strict.lua
@@ -0,0 +1,34 @@
+--
+-- strict.lua
+-- checks uses of undeclared global variables
+-- All global variables must be 'declared' through a regular assignment
+-- (even assigning nil will do) in a main chunk before being used
+-- anywhere or assigned to inside a function.
+--
+
+local mt = getmetatable(_G)
+if mt == nil then
+ mt = {}
+ setmetatable(_G, mt)
+end
+
+mt.__declared = {}
+
+mt.__newindex = function (t, n, v)
+ if not mt.__declared[n] then
+ local w = debug.getinfo(2, "S").what
+ if w ~= "main" and w ~= "C" then
+ error("assign to undeclared variable '"..n.."'", 2)
+ end
+ mt.__declared[n] = true
+ end
+ rawset(t, n, v)
+end
+
+mt.__index = function (t, n)
+ if not mt.__declared[n] and debug.getinfo(2, "S").what ~= "C" then
+ error("variable '"..n.."' is not declared", 2)
+ end
+ return rawget(t, n)
+end
+