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

  • Home
  • SEARCH
  • 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 7505937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:05:39+00:00 2026-05-29T22:05:39+00:00

I have a Lua script, where I’m trying to use hex numbers (0x..). If

  • 0

I have a Lua script, where I’m trying to use hex numbers (0x..). If I run this script in the console, with the official Windows binaries, it works fine. But if I run it in my application (simple dofile), I get

malformed number near '0x1F'

It doesn’t matter what the hex is, I always get that error, as if it wouldn’t support them. The library I’m using is Lua 5.1.4, and I’ve tried 2 different ones (the first one being one I’ve compiled myself), so that shouldn’t be the problem.

Does anyone have a clue what might be wrong here?

Edit:
It’s not the script. No matter what I do, a simple “foo = 0xf” already triggers the error, even if there’s nothing else in the file.

Update:

tonumber("0xf")

This returns nil, while

tonumber("15")

work fine. There’s definitely something wrong with hex in my libs…

  • 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-29T22:05:41+00:00Added an answer on May 29, 2026 at 10:05 pm

    Why do functions have to be different in different compilers, …why?

    Alright, the problem was that Lua tries to convert numbers into double by default. For this it uses the function “strtod”, which takes 2 arguments, the string, and a char pointer. The char pointer is supposed to point to the last position after the parsed number. Which for a hex number would mean the ‘x’, after the ‘0’. If this isn’t the case, Lua assumes an error, and gives us this nice little error message.

    I’ve compiled Lua using DMC, because I need the lib to be in OMF, and I assume others used DMC as well. But apparently DMC’s strtod works differenty, since the pointers always point to the start of the string if it’s a hex… or rather any invalid number.

    I’ve now added a little hack, which checks for the x, if conversion to double failed. Not pretty, but it works fine for now.

    int luaO_str2d (const char *s, lua_Number *result) {
      char *endptr;
      *result = lua_str2number(s, &endptr);
    
      /* Hack for DMC */
      if (endptr == s)
        if(*(s+1) == 'x' || *(s+1) == 'X')
          endptr++;
        else
          return 0; /* conversion failed */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following lua script : module(modoo,package.seeall) foo=1 bar={12,34} Which works fine using
I have this line in a Lua script that crash my software every time:
I have a lua script which is run using the command line interpreter, the
I have successfully compiled lua in my mac. It works. It runs. Now, I
I'm working with large numbers that I can't have rounded off. Using Lua's standard
This is a WoW (World of Warcraft) lua script question. Not many of these
I'm running Lighttpd on Cygwin. I have a Lua CGI script that calls a
I have a lot of lua-script with the same name used for function name
How do you end a long running Lua script? I have two threads, one
Trying to write a Lua script for Scite (something like lua-users wiki: Scite Comment

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.