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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:32:38+00:00 2026-05-31T15:32:38+00:00

I’m trying to convert some python code to Lua. What is the Lua equivalent

  • 0

I’m trying to convert some python code to Lua. What is the Lua equivalent to:

value2 = ''
key = 'cmpg'
value1 = '\x00\x00\x00\x00\x00\x00\x00\x01'
Value2 += '%s%s%s' % (key, struct.pack('>i', len(value1)), value1)
  • 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-31T15:32:39+00:00Added an answer on May 31, 2026 at 3:32 pm

    You said in a comment:

    I may be able to get by with knowing the string generated by each of
    the following: struct.pack(‘>i’,4),struct.pack(‘>i’,8), and
    struct.pack(‘>i’,10)

    The effector ‘>i’ means bigendian signed 32-bit integer. For non-negative input x, the simple Python equivalent would be

    chr((x >> 24) & 255) + chr((x >> 16) & 255) + chr((x >> 8) & 255) + chr(x & 255)

    You should be able to express that in Lua without much difficulty.

    You said in yet another comment:

    I … don’t understand an answer (@john machin)

    chr(x) is easy to find in the docs. Lua should have such a function, perhaps even with the same name.

    i >> n shifts i right by n bits. If i is unsigned, this is equivalent to i // ( 2 ** n) where // is Python’s integer floor division.

    i & 255 is a bitwise-and which is equivalent to i % 256.

    Lua should have both of those.

    The + is in this case string concatenation.

    Have a look at this:

    >>> import binascii
    >>> def pack_be_I(x):
    ...     return (
    ...         chr((x >> 24) & 255) +
    ...         chr((x >> 16) & 255) +
    ...         chr((x >>  8) & 255) +
    ...         chr(x         & 255)
    ...         )
    ...
    >>> for anint in (4, 8, 10, 0x01020304, 0x04030201):
    ...     packed = pack_be_I(anint)
    ...     hexbytes = binascii.hexlify(packed)
    ...     print anint, repr(packed), hexbytes
    ...
    4 '\x00\x00\x00\x04' 00000004
    8 '\x00\x00\x00\x08' 00000008
    10 '\x00\x00\x00\n' 0000000a
    16909060 '\x01\x02\x03\x04' 01020304
    67305985 '\x04\x03\x02\x01' 04030201
    >>>
    

    You’ll notice that the required output for 10 is '\x00\x00\x00\n' … note that '\x0a' aka '\n' aka chr(10) needs care. If you are writing this stuff to a file on Windows, you must open the file in binary mode ('wb', not 'w') otherwise the run-time library will insert a carriage-return byte to conform with Windows,MS-DOS,CP/M conventions for text files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
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

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.