diff --git a/SConstruct b/SConstruct
index c27ab06..47a1005 100644
--- a/SConstruct
+++ b/SConstruct
@@ -198,6 +198,9 @@ vars.AddVariables(
   BoolVariable(     'optram',
                     'enables Lua Tiny RAM enhancements',
                     True ),
+  BoolVariable(     'luac',
+                    'builds Lua compiler. It can then be used from the eLua shell',
+                    False ),
   MatchEnumVariable('boot',
                     'boot mode, standard will boot to shell, luarpc boots to an rpc server',
                     'standard',
@@ -364,7 +367,8 @@ if not GetOption( 'help' ):
   # Lua source files and include path
   lua_files = """lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c
     lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c
-    ldblib.c liolib.c lmathlib.c loslib.c ltablib.c lstrlib.c loadlib.c linit.c lua.c lrotable.c legc.c"""
+    ldblib.c liolib.c lmathlib.c loslib.c ltablib.c lstrlib.c loadlib.c linit.c lua.c lrotable.c legc.c
+    luac.c print.c"""
 
   lua_full_files = " " + " ".join( [ "src/lua/%s" % name for name in lua_files.split() ] )
 
@@ -381,6 +385,7 @@ if not GetOption( 'help' ):
     conf.env.Append(CPPDEFINES = ['ELUA_ENDIAN_LITTLE'])
   conf.env.Append(CPPPATH = ['src/modules', 'src/platform/%s' % platform])
   conf.env.Append(CPPDEFINES = {"LUA_OPTIMIZE_MEMORY" : ( comp['optram'] != 0 and 2 or 0 ) } )
+  conf.env.Append(CPPDEFINES = {"LUA_COMPILER" : ( comp['luac'] != 0 and 1 or 0 ) } )
 
   # Additional libraries
   local_libs = ''
diff --git a/build_elua.lua b/build_elua.lua
index b400580..334777a 100755
--- a/build_elua.lua
+++ b/build_elua.lua
@@ -213,6 +213,7 @@ builder:add_option( 'allocator', 'select memory allocator', 'auto', { 'newlib',
 builder:add_option( 'board', 'selects board for target (cpu will be inferred)', 'auto', { utils.table_keys( board_list ), 'auto' } )
 builder:add_option( 'toolchain', 'specifies toolchain to use (auto=search for usable toolchain)', 'auto', { utils.table_keys( toolchain_list ), 'auto' } )
 builder:add_option( 'optram', 'enables Lua Tiny RAM enhancements', true )
+builder:add_option( 'luac', 'builds Lua compiler. It can then be used from the eLua shell', false )
 builder:add_option( 'boot', 'boot mode, standard will boot to shell, luarpc boots to an rpc server', 'standard', { 'standard' , 'luarpc' } )
 builder:add_option( 'romfs', 'ROMFS compilation mode', 'verbatim', { 'verbatim' , 'compress', 'compile' } )
 builder:add_option( 'cpumode', 'ARM CPU compilation mode (only affects certain ARM targets)', nil, { 'arm', 'thumb' } )
@@ -395,7 +396,7 @@ if platform_list[ platform ].big_endian then addm( "ELUA_ENDIAN_BIG" ) else addm
 if platform == 'sim' then addm( { "ELUA_SIMULATOR", "ELUA_SIM_" .. cnorm( comp.cpu ) } ) end
 
 -- Lua source files and include path
-exclude_patterns = { "^src/platform", "^src/uip", "^src/serial", "^src/luarpc_desktop_serial.c", "^src/linenoise_posix.c", "^src/lua/print.c", "^src/lua/luac.c" }
+exclude_patterns = { "^src/platform", "^src/uip", "^src/serial", "^src/luarpc_desktop_serial.c", "^src/linenoise_posix.c" }
 local source_files = utils.get_files( "src", function( fname )
   fname = fname:gsub( "\\", "/" )
   local include = fname:find( ".*%.c$" )
@@ -409,6 +410,7 @@ local uip_files = " " .. utils.prepend_path( "uip_arp.c uip.c uiplib.c dhcpc.c p
 
 addi{ { 'inc', 'inc/newlib',  'inc/remotefs', 'src/platform', 'src/lua' }, { 'src/modules', 'src/platform/' .. platform }, "src/uip", "src/fatfs" }
 addm( "LUA_OPTIMIZE_MEMORY=" .. ( comp.optram and "2" or "0" ) )
+addm( "LUA_COMPILER=" .. ( comp.luac and "1" or "0" ) )
 addcf( { '-Os','-fomit-frame-pointer' } )
 
 -- Toolset data (filled by each platform in part)
diff --git a/cross-lua.lua b/cross-lua.lua
index b416573..796941d 100644
--- a/cross-lua.lua
+++ b/cross-lua.lua
@@ -7,7 +7,7 @@ builder:init( args )
 builder:set_build_mode( builder.BUILD_DIR )
 
 local output = 'luac.cross'
-local cdefs = '-DLUA_CROSS_COMPILER'
+local cdefs = '-DLUA_CROSS_COMPILER -DLUA_COMPILER=0'
 
 -- Lua source files and include path
 local lua_files = [[lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c
diff --git a/cross-lua.py b/cross-lua.py
index 86b8fb8..57f5132 100644
--- a/cross-lua.py
+++ b/cross-lua.py
@@ -1,7 +1,7 @@
 import os, sys 
 
 output = 'luac.cross'
-cdefs = '-DLUA_CROSS_COMPILER'
+cdefs = '-DLUA_CROSS_COMPILER -DLUA_COMPILER=0'
 
 # Lua source files and include path
 lua_files = """lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c
diff --git a/src/lua/lua.h b/src/lua/lua.h
index bf9145c..40203db 100644
--- a/src/lua/lua.h
+++ b/src/lua/lua.h
@@ -371,6 +371,7 @@ struct lua_Debug {
 /* }====================================================================== */
 
 int lua_main( int argc, char **argv );
+int luac_main( int argc, char **argv );
 
 /******************************************************************************
 * Copyright (C) 1994-2008 Lua.org, PUC-Rio.  All rights reserved.
diff --git a/src/lua/luac.c b/src/lua/luac.c
index 3746997..f8a82ba 100644
--- a/src/lua/luac.c
+++ b/src/lua/luac.c
@@ -12,6 +12,8 @@
 #define luac_c
 #define LUA_CORE
 
+#ifdef LUA_COMPILER
+
 #include "lua.h"
 #include "lauxlib.h"
 
@@ -23,7 +25,20 @@
 #include "lstring.h"
 #include "lundump.h"
 
+#if LUA_COMPILER
+#include <setjmp.h>
+#define FATAL_RET_VALUE  -1		/* used in fatal() */
+#define CANNOT_RET_VALUE -2		/* used in cannot() */
+#define USAGE_RET_VALUE  -3		/* used in usage() */
+static jmp_buf ebuf;			/* for 'env' in setjmp & longjmp */
+#endif // #if LUA_COMPILER
+
+#if LUA_COMPILER
+#define PROGNAME	"/mmc/luac"     /* default program name for luac running on MCU */
+#else
 #define PROGNAME	"luac"		/* default program name */
+#endif // #if LUA_COMPILER
+
 #define	OUTPUT		PROGNAME ".out"	/* default output file */
 
 static int listing=0;			/* list bytecodes? */
@@ -37,13 +52,21 @@ static DumpTargetInfo target;
 static void fatal(const char* message)
 {
  fprintf(stderr,"%s: %s\n",progname,message);
+#if LUA_COMPILER
+ longjmp(ebuf, FATAL_RET_VALUE);
+#else
  exit(EXIT_FAILURE);
+#endif // #if LUA_COMPILER
 }
 
 static void cannot(const char* what)
 {
  fprintf(stderr,"%s: cannot %s %s: %s\n",progname,what,output,strerror(errno));
+#if LUA_COMPILER
+ longjmp(ebuf, CANNOT_RET_VALUE);
+#else
  exit(EXIT_FAILURE);
+#endif // #if LUA_COMPILER
 }
 
 static void usage(const char* message)
@@ -66,7 +89,11 @@ static void usage(const char* message)
  "  -cce endian     cross-compile with given endianness ('big' or 'little')\n"
  "  --       stop handling options\n",
  progname,Output);
+#if LUA_COMPILER
+ longjmp(ebuf, USAGE_RET_VALUE);
+#else
  exit(EXIT_FAILURE);
+#endif // #if LUA_COMPILER
 }
 
 #define	IS(s)	(strcmp(argv[i],s)==0)
@@ -216,7 +243,11 @@ static int pmain(lua_State* L)
  return 0;
 }
 
+#if LUA_COMPILER
+int luac_main(int argc, char* argv[])
+#else
 int main(int argc, char* argv[])
+#endif // #if LUA_COMPILER
 {
  lua_State* L;
  struct Smain s;
@@ -229,6 +260,10 @@ int main(int argc, char* argv[])
  target.lua_Number_integral=(((lua_Number)0.5)==0);
  target.is_arm_fpa=0;
 
+#if LUA_COMPILER
+ int f=setjmp(ebuf);
+ if (f == 0) {
+#endif
  int i=doargs(argc,argv);
  argc-=i; argv+=i;
  if (argc<=0) usage("no input files given");
@@ -238,5 +273,20 @@ int main(int argc, char* argv[])
  s.argv=argv;
  if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));
  lua_close(L);
+#if LUA_COMPILER
+ }
+ /*
+  * If we're using this on the MCU,
+  * set these variables to their
+  * default values before return;
+  */
+ listing=0;                   		/* list bytecodes? */
+ dumping=1;                   		/* dump bytecodes? */
+ stripping=0;                 		/* strip debug information? */
+ output=Output;       			/* actual output file name */
+ progname=PROGNAME;   			/* actual program name */
+#endif
  return EXIT_SUCCESS;
 }
+
+#endif // #ifdef LUA_COMPILER
diff --git a/src/shell.c b/src/shell.c
index 8de8a1b..a222d82 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -68,6 +68,7 @@ static void shell_help( int argc, char **argv )
   printf( "  ls or dir   - lists filesystems files and sizes\n" );
   printf( "  cat or type - lists file contents\n" );
   printf( "  lua [args]  - run Lua with the given arguments\n" );
+  printf( "  luac [args]  - run Lua compiler with the given arguments\n" );
   printf( "  recv [path] - receive a file via XMODEM. If path is given save it there, otherwise run it.\n");
   printf( "  cp <src> <dst> - copy source file 'src' to 'dst'\n" );
   printf( "  wofmt       - format the internal WOFS\n" );
@@ -82,6 +83,17 @@ static void shell_lua( int argc, char **argv )
   clearerr( stdin );
 }
 
+// 'luac' handler
+static void shell_luac( int argc, char **argv )
+{
+#if LUA_COMPILER
+  luac_main( argc, argv );
+  clearerr( stdin );
+#else
+  printf( "'luac' support not compiled; cannot invoke Lua compiler\n" );
+#endif // #if LUA_COMPILER
+}
+
 // 'recv' handler
 static void shell_recv( int argc, char **argv )
 {
@@ -403,6 +415,7 @@ static const SHELL_COMMAND shell_commands[] =
 {
   { "help", shell_help },
   { "lua", shell_lua },
+  { "luac", shell_luac },
   { "recv", shell_recv },
   { "ver", shell_ver },
   { "exit", NULL },
