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 3220264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:44:29+00:00 2026-05-17T15:44:29+00:00

I needed to create a custom file format with embedded meta information. Instead of

  • 0

I needed to create a custom file format with embedded meta information. Instead of whipping up my own format I decide to just use Lua.

texture
{
   format=GL_LUMINANCE_ALPHA;
   type=GL_UNSIGNED_BYTE;
   width=256;
   height=128;
   pixels=[[
<binary-data-here>]];
}

texture is a function that takes a table as its sole argument. It then looks up the various parameters by name in the table and forwards the call on to a C++ routine. Nothing out of the ordinary I hope.

Occasionally the files fail to parse with the following error:

my_file.lua:8: unexpected symbol near ']'

What’s going on here?
Is there a better way to store binary data in Lua?


Update

It turns out that storing binary data is a Lua string is non-trivial. But it is possible when taking care with 3 sequences.

  • Long-format-string-literals cannot have an embedded closing-long-bracket (]], ]=], etc).
    This one is pretty obvious.

  • Long-format-string-literals cannot end with something like ]== which would match the chosen closing-long-bracket.
    This one is more subtle. Luckily the script will fail to compile if done wrong.

  • The data cannot embed \n or \r.
    Lua’s built in line-end processing messes these up. This problem is much more subtle. The script will compile fine but it will yield the wrong data. 0x13 => 0x10, 0x1013 => 0x10, etc.

To get around these limitations I split the binary data up on \r, \n, then pick a long-bracket that works, finally emit Lua that concats the various parts back together. I used a script that does this for me.
input: XXXX\nXX]]XX\r\nXX]]XX]=

texture
{
  --other fields omitted      
  pixels= '' ..
     [[XXXX]] ..
     '\n' ..
     [=[XX]]XX]=] ..
     '\r\n' ..
     [==[XX]]XX]=]==];
}
  • 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-17T15:44:30+00:00Added an answer on May 17, 2026 at 3:44 pm

    Lua is able to encode most characters in long bracket format including nulls. However, Lua opens the script file in text mode and this causes some problems. On my Windows system the following characters have problems:

    Char code(s)      Problem
    --------------    -------------------------------
    13 (CR)           Is translated to 10 (LF)
    13 10 (CR LF)     Is translated to 10 (LF)
    26 (EOF)          Causes "unfinished long string near '<eof>'"
    

    If you are not using windows than these may not cause problems, but there may be different text-mode based problems.


    I was only able to produce the error you received by encoding multiple close brackets:

    a=[[
    ]]] --> a.lua:2: unexpected symbol near ']'
    

    But, this was easily fixed with the following:

    a=[==[
    ]]==]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I came to a point where I needed to create a custom query
I'm looking to build into an application some custom logging information to use later
Whenever I have needed to create a class file from an XML XSD schema,
For my project I needed to create a custom terminal-like window and connect to
I am trying to figure out how to use/create a custom control in ASP.NET
I needed to create an application using Struts2 as MVC,Hibernate for data access and
What CSS is needed to create such an HTML layout: +--[li]---------------------------------------------+ |+--[div]-------------------------------------++---+| || A
I recently needed to create speech bubbles. To create the little triangular tip at
which framework helps in reducing the number of lines of code needed to create
I'm reaaallly new at JSON, but here's what I got. I needed to create

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.