lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Scenario 2:
> Compile the following script
>
> t001 = {t001_name = "mytable"}
>
> Result:
> a chunk about 0x45 bytes long. A look into the binary chunk reveals
> no such symbols like t001, t001_name or mytable.

Both luac and string.dump *do* include these strings (of course.)  The
simplest way (in Lua 5 that is) to compile your own chunks is by using
string.dump.  (In Lua 4 it is *much* more involved unfortunately.)  Example:

-- compile "test.lua" to "test.lc"
-- (no error checking)  :-)

local chunk = loadfile "test.lua"
local code = string.dump(chunk)

local file = io.open("test.lc", "wb")
file:write(code)
file:close()


Now you can load / execute the test.lc script as usual:

    dofile "test.lc"
    loadfile "test.lc" ()

--
Wim