lua-users home
lua-l archive

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


Olexa, I really need the ability to strip debug information from the binary, so string dump will not work, it is what I have been doing.

the 'assembler style' listing I always want, under certain conditions, i want a binary, under further conditions when I want a binary, I want to strip the debug information from the binary.  so I am stuck on luac.  because I dont know how to do that with string.dump or loadfile.

the issue here is can I recieve the binary and the assembler style listing (I call this an intermediate respresentation of a program (hence irp) if so I can direct where they write, and n the case where I am only after the irp, I can write the bin to a tempfile, or if I can receive it in a parm, ignore it.  Thanks. 

From: Olexa Bilaniuk <obilaniu@gmail.com>
Sent: Friday, September 22, 2023 13:48
To: Lua mailing list <lua-l@lists.lua.org>
Subject: Re: cannot get luac.exe to work.
 
Make that

      local listing = io.popen('luac -p -l "'..filename..'"', 'r'):read('*a')

sorry


Olexa Bilaniuk

On Fri, Sep 22, 2023 at 2:47 PM Olexa Bilaniuk <obilaniu@gmail.com> wrote:
>
> Hello Ron,
>
> The mode for reading isn't "*all" but "*a", that's the most obvious explanation.
>
> However I will note in respect of
>
>     luac.exe -o /Plugins/file.lua -l /Plugins/QSRC/file.lua
>
> that you are outputting (-o) to a file called something.lua but it's
> not really a ".lua" source file - it's bytecode.
>
> You know, it might be easier, for what you're trying to accomplish, to do
>
>     local function compile(filename)
>       -- Obtain bytecode without listing
>       local bytecode = string.dump(loadfile(filename))
>
>       -- Obtain listing without bytecode
>       local phandle = io.popen('luac -p -l "'..filename..'"', 'r'):read('*a')
>       collectgarbage("collect") -- Just in case handles not insta-collected
>
>       return bytecode, listing
>     end
>
> which requires no privileges on no executables and doesn't output to
> the filesystem but to strings in the Lua program. Then you can solve
> separately the problem of writing binary strings to the right files.
>
>
>
> Olexa Bilaniuk
>
>
>
>
> On Fri, Sep 22, 2023 at 1:27 PM Ron Unknown <qgenesist@hotmail.com> wrote:
> >
> > Hello Olexa,
> >
> > this works perfectly to get the 'assembler' output. Thanks.
> >  luac.exe -p -l file.lua
> >
> > **under certain circumstances I also want a binary executable file.
> >
> > this is the function to create the binary file:
> >
> > local function crt_bin(cmdstr)
> >
> >   hdl_cmd = io.popen(cmdstr, 'r')
> >   hdl_cmd:flush()
> >   rtxdta, _err = hdl_cmd:read('*all')
> >   hdl_cmd:close()
> >   hdl_cmd = nil
> >
> >   if _err then onerr(_err) end
> > end
> >
> > this works perfectly and does what I want from the command line:
> >  luac.exe -o /Plugins/file.lua -l /Plugins/QSRC/file.lua
> >
> > however, when I run it through the function io.popen I get: directory not found in rtxdta and the binary is not produced.
> > ok, I will do it just like the one that works
> >  luac.exe -l /Plugins/QSRC/file.lua
> > _err is nil, nothing returned in rtxdta, not in luac.out
> > ok, try this one
> >  luac.exe - -l /Plugins/QSRC/file.lua
> > _err is nil, nothing returned in rtxdta,not in luac.out
> > try them with a mode of 'rb'
> > same result.
> >
> > what do I have to do to accomplish this?  thank you.
> > ________________________________
> > From: Olexa Bilaniuk <obilaniu@gmail.com>
> > Sent: Wednesday, September 20, 2023 21:42
> > To: Lua mailing list <lua-l@lists.lua.org>
> > Subject: Re: cannot get luac.exe to work.
> >
> > Hello Ron,
> >
> > I'm not an expert in Windows, but if this can help a bit:
> >
> > 1. I notice your paths have spaces inside them, which explains why you
> > quote things. But you have to be careful when you use functions like
> > io.popen() that take a single string; That Lua function hands its
> > string straight down to the C function _popen() on Windows, and then
> > that function uses whatever rules it uses to parse the string back
> > into an array of arguments.
> >
> > 2. Some of your files have exclamation marks as well (!!) On a POSIX
> > shell, not even a double-quote shields an exclamation mark enough, it
> > may be necessary to use single quotes. On Windows I don't know what it
> > does.
> >
> > 3. I'll simplify from now on the notation:
> >
> >         luac.exe -l file.lua > file.irp
> >
> >     This works in the shell because it uses a shell redirect. At least
> > on Linux, luac *never* sees the ">" as an argument, and all it sees is
> > ["luac.exe", "-l", "file.lua"]. It writes the compiled code to the
> > default output filename, called "luac.out", and prints to standard
> > output the listing, but standard output gets redirected to "file.irp".
> >
> >     I am not sure if the C function _popen(), which io.popen() is
> > based on Windows, interprets its command string through a shell. If it
> > *does*, you have to be more careful about quoting, but redirections
> > work; whereas if it *does not*, then it will not understand the
> > redirect.
> >
> > 4. You say you use io.popen() with the "w" mode. That's unfortunate,
> > because you don't need to give luac any standard input and it doesn't
> > take any, but you *do* need to read the standard output to get the
> > listing. I recommend the "r" mode.
> >
> > 5. The commands
> >
> >         luac.exe -l file.lua > file.irp
> >         luac.exe -l file.lua -o file.irp
> >
> >     are not equivalent. The former compiles "file.lua" to bytecode in
> > "luac.out" and the listing to "file.irp". The latter does not even run
> > because after luac sees the first thing it interprets as a filename
> > ("file.lua"), it assumes everything that follows is a Lua filename to
> > be compiled as well. "-o" is not a filename.
> >
> > 6. A slight improvement is
> >
> >         luac.exe -o file.irp -l file.lua
> >
> >     This will actually run, and compile "file.lua" to bytecode in
> > "file.irp", overriding the default output filename, and prints to
> > standard output the listing. But that's not what you wanted; as I
> > gather it, you want the listing in "file.irp". Unfortunately there is
> > no way for you to indicate a file to write the listing to.
> >
> > 7. Most appropriate for you is, I believe,
> >
> >         luac.exe -p -l file.lua
> >
> >     This uses the "parse only" flag of Luac, and spits out the listing
> > to standard output. From there, a redirection will take the listing to
> > wherever you want to have it in the shell, or else io.popen("luac.exe
> > -p -l file.lua", "r") with the "r" mode will let you capture the
> > listing from luac's standard output with a :read("*a") . Most
> > importantly, luac will not create an output file, "luac.out" or
> > otherwise.
> >
> > I hope this will be useful to you.
> >
> >
> > Sincerely,
> >
> >
> > Olexa Bilaniuk
> >
> >
> >
> > On Wed, Sep 20, 2023 at 7:47 PM Ron Unknown <qgenesist@hotmail.com> wrote:
> > >
> > > I am on windows 11, and use a program called Family Historian https://www.family-historian.co.uk/
> > >
> > > Family Historian uses Lua for plugins they will only use from their Plugins folder, not any subfolders.
> > > Family Historian  version 6.2.7 uses Lua version 5.1 (I do not know the variant beyond that)
> > > Family Historian  version 7.0.x uses Lua version 5.3 (I do not know the variant beyond that)
> > >
> > > I have downloaded the 5.1.5 binaries  in both 32 and 64 bit (there is no difference in the outcome)
> > > I :gsub('\\', '/') since windows has understood '/' since windows 98 and the '\\' repeats throughout are tiresome.
> > >
> > > from a non-elevated command prompt:
> > > the very first issue I ran into was luac.out access denied, so in Windows/system32 I have an luac.out with full access for all and no longer receive that message.
> > >
> > >  "C:/Program Files (x86)/LUAC/5.1/luac5.1.exe" -l "C:/ProgramData/Calico Pie/Family Historian/Plugins/!!XPcall.fh_lua" > "C:/ProgramData/Calico Pie/Family Historian/Plugins/IRP/5.1/!!XPcall.irp"
> > > this works whether the outfile exists or not on the command line.
> > >
> > > so, I am ready to run it through my program:
> > >  "C:/Program Files (x86)/LUAC/5.1/luac5.1.exe" -l "C:/ProgramData/Calico Pie/Family Historian/Plugins/!!XPcall.fh_lua" > "C:/ProgramData/Calico Pie/Family Historian/Plugins/IRP/5.1/!!XPcall.irp"
> > > using io.popen(... , 'w')
> > > result:  No such file or directory
> > >
> > > I posit that luac will not understand the redirection pipe:
> > >  "C:/Program Files (x86)/LUAC/5.1/luac5.1.exe" -l  "C:/ProgramData/Calico Pie/Family Historian/Plugins/!!XPcall.fh_lua" -o "C:/ProgramData/Calico Pie/Family Historian/Plugins/IRP/5.1/!!XPcall.irp"
> > > result:  No such file or directory
> > >
> > > ok, create the file before you output the listing:
> > > result:  No such file or directory
> > >
> > > Yes there is, I just created it.
> > >
> > > take it back out to the non-elevated command prompt.
> > > cannot open -o: No such file or directory
> > >
> > > aha, there is some type of error I cannot understand in my command strings when run thru io.popen (or os.execute or laucom) ,  or on the command line,  and the error are from luac.exe
> > >
> > > QUESTIONS:
> > > 1) so what does the command string have to look like?
> > >  "C:/Program Files (x86)/LUAC/5.1/luac5.1.exe" -l  "C:/ProgramData/Calico Pie/Family Historian/Plugins/!!XPcall.fh_lua" -o "C:/ProgramData/Calico Pie/Family Historian/Plugins/IRP/5.1/!!XPcall.irp"
> > >
> > > additonally, under some circumstances I want to create a binary object.
> > > "C:/Program Files (x86)/LUAC/5.1/luac5.1.exe" -t -s  "C:/ProgramData/Calico Pie/Family Historian/Plugins/QSRC/QSYS.lua" -o "C:/ProgramData/Calico Pie/Family Historian/Plugins/QSYS.lua"  I understand that I may not use -t on 5.1 compiles.
> > >
> > > result:  No such file or directory
> > > 2, 3) so what does that command string have to look like, and do I have to 'wb' for this?
> > >
> > > 4_) do I need to create empty supplied outfiles, or does luac create them (or overwrite them if they exist)?
> > >
> > > I can supply the lua code (it uses several requires that I would have to supply and it is geared only to Family Historian paths, etc) but I do not feel the errors are in the general code, just the assembling of the command string)
> > >
> > > Thank you,
> > > Ronald Melby
> > >