Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7603557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:41:12+00:00 2026-05-30T23:41:12+00:00

I’ve embedded lua together with a bytecode chunk into a project written in C.

  • 0

I’ve embedded lua together with a bytecode chunk into a project written in C.
Now when I extend my lua code base by adding .lua files, is there a way to keep this code in a single bytecode chunk?

(I know how to load multiple bytecode chunks. But making it load a single chunk and then forgetting about the glue code would just seem comfortable.)

I tried to use textual inclusion, but it seems there’s no keyword for this in Lua.
“Require” and “dofile” look at the files at run time, so the resulting bytecode after running “lua -b …” won’t include the code of those files.

And there’s no way for combining bytecode files either, is there? I mean so that, when creating a bytecode file, the “require” command would add the code of all those files into one bytecode file.

PS: Michal Kottman’s answer works for Lua, which is what I asked for. I thought Lua and LuaJIT would work the same way. They don’t. To combine multiple .lua files to one LuaJIT bytecode file, should one

  • use “LuaJIT -b” (seems not to work)
  • compile Lua’s luac.c with LuaJIT sources
  • emulate luac.c with lua commands (without C API) ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:41:13+00:00Added an answer on May 30, 2026 at 11:41 pm

    You can combine multiple files into a single file using luac. When run, all the chunks from the source files are executed in the order they were added to the compiled file:

    $ echo "x=1"         > l1.lua
    $ echo "y=2"         > l2.lua
    $ echo "print(x, y)" > l3.lua
    $ luac -o run.luac l1.lua l2.lua l3.lua
    $ lua run.luac
    1   2
    

    You can load this file into Lua from C using luaL_loadfile, which places a function on the top of the stack if it loaded succesfully. Then you can just run this function using lua_call to run all the combined compiled files.

    Note that you can embed the contents of the compiled file as a string into your project, no need to keep it in external file.

    Update for LuaJIT 2

    As you have found, you can use the Lua Compiler in Lua to get a combined file which can be loaded as previously noted. This is a simplified version, which outputs to stdout:

    -- http://lua-users.org/wiki/LuaCompilerInLua
    -- compile the input file(s) passed as arguments and output them combined to stdout
    local chunk = {}
    for _, file in ipairs(arg) do
      chunk[#chunk + 1] = assert(loadfile(file))
    end
    if #chunk == 1 then
      chunk = chunk[1]
    else
      -- combine multiple input files into a single chunk
      for i, func in ipairs(chunk) do
        chunk[i] = ("loadstring%q(...);"):format(string.dump(func))
      end
      chunk = assert(loadstring(table.concat(chunk)))
    end
    io.write(string.dump(chunk))
    

    For the previous sample, you can use it as follows:

    $ luajit combine.lua l1.lua l2.lua l3.lua > out.ljc
    $ luajit out.ljc
    1   2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.