summaryrefslogtreecommitdiff
path: root/etc
diff options
context:
space:
mode:
Diffstat (limited to 'etc')
-rw-r--r--etc/Makefile32
-rw-r--r--etc/README41
-rw-r--r--etc/bin2c.c6
-rw-r--r--etc/def.lua9
-rw-r--r--etc/lua.icobin0 -> 1078 bytes
-rw-r--r--etc/lua.magic10
-rw-r--r--etc/lua.xpm44
-rw-r--r--etc/min.c25
-rw-r--r--etc/stdcall.lua10
-rw-r--r--etc/trace.c35
10 files changed, 171 insertions, 41 deletions
diff --git a/etc/Makefile b/etc/Makefile
index 216d3ef6..a7768697 100644
--- a/etc/Makefile
+++ b/etc/Makefile
@@ -4,21 +4,35 @@ LUA= ..
include $(LUA)/config
-ALL= bin2c min trace
+LIBLUA=$(LIB)/liblua.a
+ALL= bin2c min trace lua.def
+
+x:
+ @echo 'choose a target:' all $(ALL)
all: $(ALL)
-bin2c: bin2c.c
- $(CC) -o $@ $<
+bin2c: bin2c.c
+ $(CC) $(CFLAGS) -o $@ $@.c
+
+min: min.c $(LIBLUA)
+ $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua
+
+trace: trace.c $(LIBLUA)
+ $(CC) $(CFLAGS) -o $@ $@.c -L$(LIB) -llua -llualib -lm
+
+def: lua.def
-min: min.c $(LIB)/liblua.a
- $(CC) $(CFLAGS) -o $@ $< -L$(LIB) -llua
+lua.def: $(INC)/lua.h
+ $(BIN)/lua def.lua < $(INC)/lua.h > $@
+ # cat $(INC)/l*.h | $(BIN)/lua def.lua > $@
-trace: trace.c $(LIB)/liblua.a
- $(CC) $(CFLAGS) -o $@ $< -L$(LIB) -llua
+stdcall:
+ mkdir -p Stdcall
+ grep -l _API $(LUA)/src/*.[ch] $(LUA)/src/*/*.[ch] | xargs -n1 -i echo $(BIN)/lua stdcall.lua '<{}' '>Stdcall/{}'
-$(LIB)/liblua.a:
- cd ../src; make
+$(LIBLUA):
+ cd ../src; $(MAKE)
clean:
rm -f $(ALL)
diff --git a/etc/README b/etc/README
index 002190ae..eaae1c3d 100644
--- a/etc/README
+++ b/etc/README
@@ -2,25 +2,42 @@ This directory contains some code that might be useful.
bin2c.c
This program converts files to byte arrays that are automatically
- run with lua_dobuffer.
- This allows C programs to include all necessary Lua code, even in
- precompiled form.
- Even if the code is included in source form, bin2c is useful because it
- avoids the hassle of having to quote special characters in C strings.
+ run with lua_dobuffer. This allows C programs to include all necessary
+ Lua code, even in precompiled form. Even if the code is included in
+ source form, bin2c is useful because it avoids the hassle of having to
+ quote special characters in C strings.
Example of usage: Run bin2c file1 file2 ... > init.h. Then, in your C
program, just do #include "init.h" anywhere in the *body* of a
function. This will be equivalent to calling
- lua_dofile("file1"); lua_dofile("file2"); ...
+ lua_dofile(L,"file1"); lua_dofile(L,"file2"); ...
+ Note that the Lua state is called "L". If you use a different name,
+ say "mystate", just #define L mystate before #include "init.h".
+
+def.lua
+ A Lua script for creating .DEF for Windows DLLs.
+ Just do "make def" to create lua.def.
min.c
- The smallest Lua interpreter possible.
+ A minimal Lua interpreter.
+
+lua.ico
+ A Lua icon for Windows.
+ It was drawn by hand by Markus Gritsch <gritsch@iue.tuwien.ac.at>.
+
+lua.xpm
+ The same icon as lua.ico, but in XPM format.
+ It was converted with ImageMagick by Andy Tai <andy@exp.com>.
+
+lua.magic
+ Data for teaching file(1) about Lua precompiled chunks.
+
+stdcall.lua
+ A Lua script for changing the calling convention to __stdcall.
+ Do "make stdcall" and new modules will be created in stdcall/.
setfallback.lua
- An implementation of fallbacks on top of tag methods.
- Useful if you have Lua code written for version 2.5 or earlier,
- which uses setfallback.
- If you have C code that uses lua_setfallback, then define LUA_COMPAT2_5
- before building Lua (see config).
+ A Lua implementation of fallbacks on top of tag methods.
+ You only need this module if you have Lua code that uses setfallback.
trace.c
A simple execution tracer. An example of how to use the debugging hooks.
diff --git a/etc/bin2c.c b/etc/bin2c.c
index fca82a55..ac95a6e8 100644
--- a/etc/bin2c.c
+++ b/etc/bin2c.c
@@ -2,7 +2,7 @@
* bin2c.c
* convert binary files to byte arrays
* Luiz Henrique de Figueiredo (lhf@tecgraf.puc-rio.br)
-* 24 Nov 98 12:15:27
+* 11 Sep 2000 22:37:14
*/
#include <ctype.h>
@@ -45,7 +45,7 @@ void fdump(char* fn, int n)
void emit(char* fn, int n)
{
- printf(" lua_dobuffer(B%d,sizeof(B%d),\"%s\");\n",n,n,fn);
+ printf(" lua_dobuffer(L,B%d,sizeof(B%d),\"%s\");\n",n,n,fn);
}
int main(int argc, char* argv[])
@@ -61,7 +61,7 @@ int main(int argc, char* argv[])
{
int i;
printf("/* #include'ing this file in a C program is equivalent to calling\n");
- for (i=1; i<argc; i++) printf(" lua_dofile(\"%s\");\n",argv[i]);
+ for (i=1; i<argc; i++) printf(" lua_dofile(L,\"%s\");\n",argv[i]);
printf("*/\n");
for (i=1; i<argc; i++) fdump(argv[i],i);
for (i=1; i<argc; i++) emit(argv[i],i);
diff --git a/etc/def.lua b/etc/def.lua
new file mode 100644
index 00000000..736e32cd
--- /dev/null
+++ b/etc/def.lua
@@ -0,0 +1,9 @@
+-- def.lua
+-- make .DEF file from lua.h
+-- usage: lua def.lua <lua.h >lua.def
+
+T=read"*a"
+write("LIBRARY LUA\nVERSION ")
+gsub(T,"LUA_VERSION.-(%d+%.%d+)",write)
+write("\nEXPORTS\n")
+gsub(T,"(lua_%w+)%s+%(",function (f) write(" ",f,"\n") end)
diff --git a/etc/lua.ico b/etc/lua.ico
new file mode 100644
index 00000000..ccbabc4e
--- /dev/null
+++ b/etc/lua.ico
Binary files differ
diff --git a/etc/lua.magic b/etc/lua.magic
new file mode 100644
index 00000000..eb78f8d0
--- /dev/null
+++ b/etc/lua.magic
@@ -0,0 +1,10 @@
+
+# Lua precompiled files
+0 string \33Lua precompiled chunk for Lua
+>4 byte 0x23 2.3
+>4 byte 0x24 2.4
+>4 byte 0x25 2.5
+>4 byte 0x30 3.0
+>4 byte 0x31 3.1
+>4 byte 0x32 3.2
+>4 byte 0x40 4.0
diff --git a/etc/lua.xpm b/etc/lua.xpm
new file mode 100644
index 00000000..d3dcd379
--- /dev/null
+++ b/etc/lua.xpm
@@ -0,0 +1,44 @@
+/* XPM */
+static char *magick[] = {
+/* columns rows colors chars-per-pixel */
+"32 32 6 1",
+" c Gray0",
+". c #000000008080",
+"X c #808080808080",
+"o c #c0c0c0c0c0c0",
+"O c Gray100",
+"+ c None",
+/* pixels */
+"++++++++++++++++++++++++++ooo+++",
+"++++++++++++++++++++++++oX...Xo+",
+"++++++++++++++++++++++++X.....X+",
+"+++++++++++++++++++++++o.......o",
+"+++++++++XX......XX++++o.......o",
+"+++++++X............X++o.......o",
+"+++++o................o+X.....X+",
+"++++X..................XoX...Xo+",
+"+++X..............XXX...X+ooo+++",
+"++o.............XoOOOoX..o++++++",
+"++..............oOOOOOo...++++++",
+"+X.............XOOOOOOOX..X+++++",
+"+..............XOOOOOOOX...+++++",
+"X..............XOOOOOOOX...X++++",
+"X...............oOOOOOo....X++++",
+"................XoOOOoX.....++++",
+"....XO............XXX.......++++",
+"....XO......................++++",
+"....XO.....OX..OX.XOOOo.....++++",
+"....XO.....OX..OX.OoXXOX....++++",
+"....XO.....OX..OX....XOX....++++",
+"X...XO.....OX..OX..OOoOX...X++++",
+"X...XO.....OX..OX.OX..OX...X++++",
+"+...XOXXXX.OoXoOX.OXXXOX...+++++",
+"+X..XOOOOO.XOOXOX.XOOOXo..X+++++",
+"++........................++++++",
+"++o......................o++++++",
+"+++X....................X+++++++",
+"++++X..................X++++++++",
+"+++++o................o+++++++++",
+"+++++++X............X+++++++++++",
+"+++++++++XX......XX+++++++++++++"
+};
diff --git a/etc/min.c b/etc/min.c
index 7d45f5b6..0579ed3f 100644
--- a/etc/min.c
+++ b/etc/min.c
@@ -1,13 +1,32 @@
/*
* min.c
* a minimal Lua interpreter. loads stdin only.
-* no standard library, only builtin functions.
+* no standard library, only a "print" function.
*/
+#include <stdio.h>
#include "lua.h"
+/* a simple "print". based on the code in lbaselib.c */
+static int print(lua_State *L)
+{
+ int n=lua_gettop(L);
+ int i;
+ for (i=1; i<=n; i++)
+ {
+ if (i>1) printf("\t");
+ if (lua_isstring(L,i))
+ printf("%s",lua_tostring(L,i));
+ else
+ printf("%s:%p",lua_typename(L,lua_type(L,i)),lua_topointer(L,i));
+ }
+ printf("\n");
+ return 0;
+}
+
int main(void)
{
- lua_open();
- return lua_dofile(0);
+ lua_State *L=lua_open(0);
+ lua_register(L,"print",print);
+ return lua_dofile(L,NULL);
}
diff --git a/etc/stdcall.lua b/etc/stdcall.lua
new file mode 100644
index 00000000..7eac5c2e
--- /dev/null
+++ b/etc/stdcall.lua
@@ -0,0 +1,10 @@
+-- stdcall.lua
+-- add __stdcall where appropriate
+-- usage: lua stdcall.lua <lua.h >s_lua.h
+-- usage: lua stdcall.lua <lapi.c >s_lapi.c
+
+T=read"*a"
+T=gsub(T,"(lua_%w+%s+%()","__stdcall %1")
+T=gsub(T,"(%*lua_CFunction)","__stdcall %1")
+
+write(T)
diff --git a/etc/trace.c b/etc/trace.c
index 2c92850f..7c0b86ed 100644
--- a/etc/trace.c
+++ b/etc/trace.c
@@ -6,44 +6,51 @@
#include <stdio.h>
#include <string.h>
#include "lua.h"
+#include "lualib.h"
#include "luadebug.h"
+lua_State *lua_state = NULL;
+#define L lua_state /* lazy! */
+
static FILE* LOG; /* output file */
-static int L=0; /* indentation level */
+static int I=0; /* indentation level */
-static void linehook(int line)
+static void linehook(lua_State *L, lua_Debug *ar)
{
- fprintf(LOG,"%*sLINE(%d)\t-- %d\n",L,"",line,L);
+ fprintf(LOG,"%*sdo_line(%d)\t-- %d\n",I,"",ar->currentline,I);
}
-static void callhook(lua_Function func, char* file, int line)
+static void callhook(lua_State *L, lua_Debug *ar)
{
- fprintf(LOG,"%*sCALL('%s',%d)\t-- %d\n",L,"",file,line,L);
- if (line==0 && strcmp(file,"(return)")==0) --L; else ++L;
+ fprintf(LOG,"%*sdo_%s\t-- %p %d\n",I,"",ar->event,ar->_func,I);
+ if (*ar->event=='r') --I; else ++I;
}
void start_trace(FILE* logfile)
{
- lua_setlinehook(linehook);
- lua_setcallhook(callhook);
- lua_setdebug(1);
+ lua_setlinehook(L,linehook);
+ lua_setcallhook(L,callhook);
LOG=logfile;
}
void stop_trace(void)
{
- lua_setlinehook(NULL);
- lua_setcallhook(NULL);
- lua_setdebug(0);
+ lua_setlinehook(L,NULL);
+ lua_setcallhook(L,NULL);
fclose(LOG);
}
int main(void)
{
int rc;
- lua_open();
+ L=lua_open(0);
+ lua_baselibopen(L);
+ lua_iolibopen(L);
+ lua_strlibopen(L);
+ lua_mathlibopen(L);
+ lua_dblibopen(L);
start_trace(stderr);
- rc=lua_dofile(0);
+ rc=lua_dofile(L,0);
stop_trace();
return rc;
}