lua discussion

Started by
22 comments, last by brightening-eyes 9 years, 3 months ago

You still haven't explained what you mean by "embed lua". But it is quite common to just dump stuff at the end of the binary file, as far as I know all common executable formats don't mind (including PE32/ELF). To do this is very easy, one simple method is to write your data at the end, followed by a single 4-byte integer containing the size of your data. To decode the data, read the last 4 bytes, then read that many bytes from the end of the executable, done. You can then build a virtual filesystem on top of that blob using PhysFS or whatever. It can be tricky to actually write data back into the binary file while the process is running, but it can be done reliably (though in most cases is unnecessary, if you are just looking for a one-file download you can just deploy all your files onto disk the first time your program is run and proceed as usual afterwards). In fact, if you are looking for a read-only solution, then Hodgman's solution of an embedded binary blob is easier and less error-prone, with perhaps the caveat that it may require relinking your executable when changing the embedded data.

I honestly think you are misunderstanding what people are saying, though: Lua does not need its own executable format. It is not generally used as a standalone program (but it can be). It is usually used as scripts called from the main application and interacting with it. Why do you need your Lua scripts to be run standalone without an executable? What are you trying to do? Give more information, please!

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Advertisement

guys, executables have there own headers!

I have no clue what you want to say here. It does not seem to have any relevance to what this thread is about.

but after embed lua, do i need to run my app inside the executable?

What is app for you here? Your Lua program?

and, how to create a virtual filesystem inside an executable?

There are many ways to do that. PhysFS is commonly suggested but I personally could never like it.
It's simple to write a small tool which transforms any input file into a C++ header though. From there on it goes all the way up to more complex embedded file systems like for example the one implemented by Qt's resource system. I don't get your exact needs so making more detailed suggestions is difficult.
Windows' own resource system might be worth a look too.

i've compiled my bytecode, it cannot be runned, it depends on my application
for converting it into executable, we can do the following:
1. copy the bytecode into a buffer from memory
2. create that header, and wrapp the functions, meta tables, etc from the application
3. resolve the simbles
4. append the bytecode from the memory into executable
now, how to get the bytecode and store it in memory, how to know witch function is called, and wrapp it, how to resolve simbles, etc

I don't really understand what you are trying to do there and why. You seem to believe you need to treat your Lua code like C++ code (translate it into machine code and link it). That sounds like an awful lot of work requiring quite a lot of knowledge in a domain where hardly anyone will have any experience for practically no gain.

You have your executable (which has Lua or LuaJIT embedded). You have your Lua files (source or precompiled). At the simplest you put the Lua files next to the executable, the executable passes those files to the embedded Lua interpreter/compiler and everything runs. Good, although having the Lua files lying next to the executable might not always be desired.
Now you can put these Lua files into a container or virtual file system as sketched above. Depending on how exactly it is done their will be the container file required next to the executable or only the executable (if the data is actually burned into the executable, for example using the header method).

yes, i want to compile my lua code into stand alone executable

i want to create a game engine and with the lua scripts, create my game and compile it

firstly, can i copy the running script from memory into executable?

secondly, do i need to embed lua inside my scripts witch i need to compile?

then, when i copyed the scripts, how it can find my functions witch i've registered it to lua inside C++?

my problem is, i want to create executables from lua, i dont know witch function is currently executing from the script

about the executable offset, how can i get it?

thanks

when you can't see well like me, you can't test your applications and you can't read something

Github

ok, i've got that!, i'll work with srlua's source code in my app!

thanks everybody

when you can't see well like me, you can't test your applications and you can't read something

Github

This topic is closed to new replies.

Advertisement