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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:32:56+00:00 2026-05-11T06:32:56+00:00

how do I check the value of the top of the stack in Lua?

  • 0

how do I check the value of the top of the stack in Lua?

I have the following C++ code:

if (luaL_loadfile(L, filename) == NULL) {         return 0;// error..     }      lua_pcall(L,0,0,0); // execute the current script..      lua_getglobal(L,'variable');      if (!lua_isstring(L,-1)){ // fails this check..         lua_pop(L,1);         return 0; // error } 

The contents of the file in question is

-- A comment variable = 'MyString' 

Any ideas?

  • 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. 2026-05-11T06:32:57+00:00Added an answer on May 11, 2026 at 6:32 am

    The likely problem is that luaL_loadfile() is documented to return the same values as lua_load() or one additional error code. In either case, the return value is an int where 0 means success and a nonzero value is an error code.

    So, the test luaL_loadfile(...) == NULL is true if the file was loaded, but the code calls that an error and returns.

    The function lua_pcall() also returns a status code, and you may want to verify that as well.

    Otherwise, the script as shown does create a global variable, and lua_getglobal() would retrieve that to the stack where it could be tested with lua_isstring(), or probably more usefully let you return its value if it is sufficiently string-like with lua_tostring(). The latter function will return either a const char * pointing at a nul-terminated string, or NULL if the value at the stack index can’t be converted to a string. See the Lua reference manual as linked for the rest of the details and a caveat about using lua_tostring() inside a loop.

    Edit: I added better links to the manual in a couple of places.

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

Sidebar

Related Questions

How to check a value IS NULL [or] = @param (where @param is null)
I have a grid which has check boxes and when selecting the top chek
I've used the top voted answer from here to check if a cell value
I need to check the value of my birthdate input field. There should be
$(document).ready(function() { //Check City Value var city_value = parseInt($(#city).val()); if( city_value == 0) {
I would like to programmatically check the value of, and be able to toggle
I am looking for a concise way to check a value to see if
I'm working on a simple ASP.Net page (handler, actually) where I check the value
Which is, on average, faster - check the value then, if needed, assign, or
How do I check if my value is a integer or not? I want

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.