INSTRUCTIONS FOR USE:

Keep the web page, it explains WHY. This file cuts to the chase with the HOW... The WHY will make more
sense later, if it's a bit opaque now. Above all, explore it, it's easier to learn from breaking it so
don't worry about doing that, just make sure you start clean or you'll never know if it ever worked!

When it works, pick it apart till you know what you need and why it's there. You won't need everything
in Lua, but it helps to know what changed between the files here, and their originals. "LIBRARIES.txt"
explains how to select Lua libraries and to start writing new library code. The library files may well
be the fastest guide to writing new code, bearing in mind some points made on the LuaTools web page.

Start by unpacking the ZIP file to a base directory where you want the source code to stay, and adjust
the batch file so the path to that base directory is ready for compiling. It starts by assuming a path
to E:\CODING\COMPILER\TCC\ for the compiler, and E:\CODING\LUA\CODE_401\ for the Lua installation. The
batch file is the master copy. Batch files for new projects should be copies of it, so keep it safe!

There are three new library files: "#aux.c", "#console.c", and "#file.c", which must be copied to each
CODE_nnn directory described below. They are equally compatible in these versions of Lua, and must not
be changed unless ALL are to be changed in the same way. Compatibility is critical for easy changes of
the version used in a program. "Library Commands.txt" gives detailed explanations of their functions.

To complete the full installation, source files are needed from Lua.org: https://www.lua.org/ftp/
Up to three files are needed, depending on which versions to use. Earlier is smaller and often better.

filename          date        size    checksum (SHA256)
lua-4.0.1.tar.gz  2002-07-04  158426  DF746E149CF6939E90009D2E540EEE918D585B4D1BC6D68B19316A050D484D2A
lua-5.0.2.tar.gz  2004-03-17  190442  A6C85D85F912E1C321723084389D63DEE7660B81B8292452B190EA7190DD73BC
lua-5.4.2.tar.gz  2020-11-13  353472  11570D97E9D7303C0A59567ED1AC7C648340CD0DB10D5FD594C09223EF2F524F

The files needed to complete the system are listed below. Copy them from the source files to the named
base directory, except for the extra LUAC files in Lua v4.0.1. Those go to the Luac subdirectory.

        CODE_401:                       CODE_502:                       CODE_542:

        lcode.c                         lapi.c                          lapi.c
        lcode.h                         lapi.h                          lapi.h
        ldebug.c                        lcode.c                         lcode.c
        ldebug.h                        lcode.h                         lcode.h
        ldo.c                           ldebug.c                        lctype.c
        ldo.h                           ldebug.h                        lctype.h
        lfunc.c                         ldo.c                           ldebug.c
        lfunc.h                         ldo.h                           ldebug.h
        lgc.c                           ldump.c                         ldo.c
        lgc.h                           lfunc.c                         ldo.h
        llex.h                          lfunc.h                         ldump.c
        llimits.h                       lgc.c                           lfunc.c
        lmem.c                          lgc.h                           lfunc.h
        lmem.h                          llex.c                          lgc.c
        lobject.c                       llex.h                          lgc.h
        lobject.h                       llimits.h                       ljumptab.h
        lopcodes.h                      lmathlib.c                      llex.c
        lparser.c                       lmem.c                          llex.h
        lparser.h                       lmem.h                          llimits.h
        lstate.h                        lobject.c                       lmem.c
        lstring.c                       lobject.h                       lmem.h
        lstring.h                       lparser.c                       lobject.c
        ltable.c                        lparser.h                       lobject.h
        ltable.h                        lstate.h                        lopcodes.c
        ltm.c                           lstring.c                       lopcodes.h
        ltm.h                           lstring.h                       lopnames.h
        luadebug.h                      ltable.c                        lparser.c
        lundump.c                       ltable.h                        lparser.h
        lundump.h                       ltm.c                           lprefix.h
        lvm.c                           ltm.h                           lstate.h
        lvm.h                           lundump.c                       lstring.c
        lzio.c                          lundump.h                       lstring.h
        lzio.h                          lvm.c                           ltable.c
                                        lvm.h                           ltable.h
        LUAC:                           lzio.c                          ltm.c
        dump.c                          lzio.h                          ltm.h
        luac.h                                                          lua.hpp
        opt.c                                                           lundump.c
        print.c                                                         lundump.h
        print.h                                                         lvm.c
                                                                        lvm.h
                                                                        lzio.c
                                                                        lzio.h

Last, but not least, the compiler: http://download.savannah.gnu.org/releases/tinycc/
Put it where you want it to stay, and adjust the master batch file so it can find "tcc.exe".

filename                    date                size
tcc-0.9.25-win32-bin.zip    18-May-2009 13:14   287181

checksum (SHA256)
9643C03EE7BCE8589EB7DDA6C41F3761728CA8FDC3F1C3EBE83E3590C4B80EB3

NOTE: The file size in bytes and the SHA256 checksum are not given on the TCC page,
      but must match the values provided here. This is critical. If you have exact
      matches you can be sure things will work as they did when making this system.
      It's best to change NOTHING until you're sure you have it working as intended.

WARNING!
      DO NOT be tempted to use the TCC compiler version "tcc-0.9.27-win32-bin.zip"!
      It is badly broken. There was an effort to get a lot more GCC header support,
      but this failed. Additional support in the file "winapi-full-for-0.9.27.zip"
      was intended to give full support, but the developer warns that this may fail.
      HEED THAT WARNING! IT DOES FAIL. Stay with TCC v0.9.25 because it works. All
      three Lua variants work well with it (after a bit of modification in v5.0.2 to
      fix a known bug with LUAC and its opcodes when dynamically linking Luac with
      LUA.DLL), but also important is the file dialog made available by the "#file.c"
      library. The version of TCC listed here can make Win32 file dialogs work, and
      it's the latest version that can! It is probably not a co-incidence that later
      versions emphasised 64-bit compiling. This system is a 32-bit system, so it's
      VERY unwise to use anything but the latest and cleanest 32-bit version of TCC!
      The resulting programs may run on a 64-bit system anyway, but that's untested.

When TCC is installed (by dragging the "tcc" directory out of the ZIP and putting it where you want
it to stay), there are two extra files needed to make Win32 file dialogs work. I provide those here
to save trouble:

    COMMDLG.H       Put this in the "tcc\include\winapi" subdirectory.
    COMDLG32.DEF    Put this in the "tcc\lib" subdirectory.

To test the system, run the master batch file by double-clicking it. If everything works, there will
be 4 new files created beside it, as follows:

Lua.def             KEEP THIS ONE! This is needed for later compiling of a tool linked with LUA.DLL.
Lua.dll             KEEP THIS ONE, unless you're compiling LUA and LUAC as separate executables.
Lua.exe             KEEP THIS ONE! It's the main Lua executable.
Luac.exe            KEEP THIS ONE! It's vital for building other executables from Lua scripts.

One other tool worth having is UPX: https://upx.github.io/ (Search on the web if that address dies).
This compresses EXE and DLL files, and in combination with library exclusion and linking with a DLL,
can make tools small enough for very cheap and efficient mass distribution.


Lostgallifreyan, 14/05/2022.
