lua discussion

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

If you only need the way to create something self-running, then you can create native host (executable binary), containing lua/luajit vm, and seeking scripts appended at the end of host's file. Your application will write body of host, and append script (bytecode without debug info) to host body's tail. You can append not just single script, it might be any sort of virtual filesystem, containing group of related lua scripts.

Advertisement

If you only need the way to create something self-running, then you can create native host (executable binary), containing lua/luajit vm, and seeking scripts appended at the end of host's file. Your application will write body of host, and append script (bytecode without debug info) to host body's tail. You can append not just single script, it might be any sort of virtual filesystem, containing group of related lua scripts.

how can i do this?

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

Github

how can i do this?

You should be familiar with embedding lua first.

Because that host is nothing else than your "game engine with lua embedded in it".

There won't be any native code generated from scripts ahead-of-time, no object files, no linking, nothing that can be "included" as c++ source file.

Appended script will be just a data for the "game".

If you thought about something different, then you should clarify your intentions. What's your real target?

The way that every game I've worked on does this is, don't. Instead --
1)Compile the Lua text source into Lua bytecode (or LuaJIT bytecode) using the standard bytecode compiler.
2)Embed those bytecode files into your exe / game-data files.
3)Write some code in the EXE to execute the bytecode with the Lua (or LuaJIT) library.


No need to get hung up on compiling your lua code itself into an EXE...

i've embedded lua into my application, but after compiling my scripts into bytecode, what should i do in order to make it stand-alone without need my application?

i want to distribute my stand-alone executable to others

how can i embedd luajit into that executable?

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

Github

after compiling my scripts into bytecode, what should i do in order to make it stand-alone without need my application?

You write new application that will read and execute attached script.

You already know how to do that, because you've embedded lua in your other app.

Then you take this new executable file and store it as resource in your big app.

Now when you "compile" script into self-running app, you take that executable from resources, write into file, then append compiled bytecode to same file. Now you got self-running lua script.

how can i embedd luajit into that executable?

Probably you should start with lua. After you got it running, you can move to luajit.

Because luajit has additional libs in external lua files, you should either copy it together with resulting executable, or pack it into virtual filesystem (say, just ZIP archive) together with main script, and alter lua's "require" behaviour to read lua files from that filesystem.

i've embedded lua into my application, but after compiling my scripts into bytecode, what should i do in order to make it stand-alone without need my application?
i want to distribute my stand-alone executable to others
how can i embedd luajit into that executable?

Embed the compiled lua code into your exe (e.g. dumb/simple approach, make a program that opens binary files and emits a '.h' file containing: const static byte g_data[] = { 1,3,3,7,bytes from that file...};)
Then use the Lua/LuaJIT APIs to run than embedded code.



You say you've already embedded Lua into your engine... What does that mean? What have you actually done so far?

how can i embedd luajit into that executable?


Probably you should start with lua. After you got it running, you can move to luajit.
Because luajit has additional libs in external lua files, you should either copy it together with resulting executable, or pack it into virtual filesystem (say, just ZIP archive) together with main script, and alter lua's "require" behaviour to read lua files from that filesystem.


Where did you get that? I have successfully linked LuaJIT completely statically with nothing but the executable needed.

Where did you get that?

I didn't say those are required for normal ops, still libs is there if needed smile.png

Also, I doubt there always will be single script without any additional dependencies, like app's own precompiled libs.

So having a vfs would good anyway.

guys, executables have there own headers!

see MSDN for more information

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

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

now:

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

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