lua-users home
lua-l archive

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


Here is a sample output:

> print(string.dump(load("x=1\ny=2\nprint('hello',x,y)")))
←LuaR ☺♦ ↓ô

          @└@ü♠ A A@☺ å @ ╞Ç@ ↔@ ☻▼ Ç ♠   ♦☻   x ♥      ≡?♦☻   y ♥       @♦♠   p
rint ♦♠   hello     ☺   ☺ ←   x=1
y=2
print('hello',x,y)   ☺   ☻   ♥   ♥   ♥   ♥   ♥   ♥       ☺   ♣   _ENV
>

As seen the dump contains a copy of the original string. Oliver is right it is the debugging source information. If I do print(stirng.dump(load("x=1\ny=2\nprint('hello',x,y)","string"))) then the copy of the whole string is gone just left with 'string'

Is string.dump platform dependent like the bytecode?

Thanks,
Milind

On Wed, Nov 12, 2014 at 9:45 PM, Tim Hill <drtimhill@gmail.com> wrote:

> On Nov 12, 2014, at 7:33 PM, Milind Gupta <milind.gupta@gmail.com> wrote:
>
> Hi,
>         I have a lua script which has some scripts written inside string variables. Is it possible to have these scripts as compiled scripts so when I compile the main script using luac these scripts are not visible directly as text in the compiled file?
>        I tried to have the strings as string.dump(load(scriptAsString)) but that still has the text of the script although I see some binary characters appended.
>
> Thanks,
> Milind
>
>

string.dump() will just give you the byte codes, not the source code. Are you sure about your code? And yes, once you have the byte code you can use it as input to load() to avoid having the source code distributed. Note, however, that byte code is NOT portable and so may not load if the target platform differs from the one on which it was compiled.

—Tim