public
Description: convert Lua source code into an equivalent C source code written in terms of Lua C API calls
Homepage: http://lua-users.org/wiki/LuaToCee
Clone URL: git://github.com/davidm/lua2c.git
lua2c / clua
100755 60 lines (52 sloc) 1.131 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
#
# Shell script wrapper to convert Lua to C and optionally
# compile and run it.
#
# option -c causes compilation only (no run)
# option -C causes C source generation only (no compile or run)
 
pushd "`dirname \"$0\"`" > /dev/null
export CWD="$PWD"
popd > /dev/null
 
# You may need to change these variables:
LUA=lua
CC=gcc
CFLAGS="-O3 -fomit-frame-pointer -DNDEBUG -Wall -Ilua/src"
#CFLAGS="-O2 -DNDEBUG -Wall -Ilua/src"
#CFLAGS=-g
LFLAGS="-Llua/src -llua"
LUA2C="${LUA} $CWD/lua2c.lua"
#LUA2C="./lua2c"
 
COMPILEONLY=
if [ "$1" = "-c" ]
then
COMPILEONLY=1
  shift
elif [ "$1" = "-C" ]
then
COMPILEONLY=2
  shift
fi
if [ "$1" = "" ]
then
echo "usage: clua [options] [filename.lua] ..."
  echo " options:"
  echo " -c compile only (no run)"
  echo " -C generate C source only (no compile or run)"
  exit 1
fi
 
LUAFILE=$1
FILENAME=${LUAFILE%.*}
CFILE=${FILENAME}.c
 
LUA_PATH=$CWD/lib/?.lua ${LUA2C} ${LUAFILE} > ${CFILE} || exit 1
if [ "$COMPILEONLY" = "2" ]
then
exit 0
fi
 
${CC} ${CFLAGS} ${CFILE} -o ${FILENAME} ${LFLAGS} || exit 1
if [ "$COMPILEONLY" = "1" ]
then
exit 0
fi
 
shift
./${FILENAME} $@