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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:39:36+00:00 2026-06-09T07:39:36+00:00

I have the following C file: //thing.c #include <lua.h> #include <lauxlib.h> #include <lualib.h> #include

  • 0

I have the following C file:

//thing.c
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

#include <stdio.h>

lua_State* L;

int main(){
        L = lua_open();

        lua_dostring(L, "print(\"lua\")");
        printf("hello\n");

        return 0; }

and the following makefile:

default:
        gcc -I/usr/include/lua50 -L/usr/lib -o qwerty thing.c -llua50 -llualib50

the code builds just fine, but when I run it I get the following:

[string "print("lua")"]:1: attempt to call global `print' (a nil value)
hello

Note: I have seen the many other questions on this error, but they all deal with working directly in Lua, as opposed to with the C api. They also seem to imply that the problem is that the print function was never defined. I don’t understand this, as I can run both a lua interpreter and a lua script just fine directly from the command line.

EDIT: I am using lua 5.0

  • 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-06-09T07:39:37+00:00Added an answer on June 9, 2026 at 7:39 am

    You have to initialize the libraries in Lua. After you call lua_open, call

    luaL_openlibs(L);
    

    Edit: for Lua 5.0, I believe you’ll have to open the libraries manually. For the print function, you just need the base library:

    luaopen_base(L);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a c program #include <stdio.h> int main () { printf(Hello); } On
I have the following code: std::string cmd = sudo chmod a+x file; int r
Given I have two File objects I can think of the following implementation: public
I have following html file (1.html) and once I open it in my browser
I have following xml file: <ab> <![CDATA[ <table> <tbody> <tr> <th>abcdef</th> </tr> <tr> <p>
I have the following file structure: |- index.html vendor |- jquery.min.js (some libraries) js
I have the following file and I am using an iterator block to parse
I have the following file (above) which seems to be an Unix pipe alt
I have the following File object pointing to a directory via symbolic link, File
I have the following file dupeExtracter.rb to remove duplicate entries from a DB table

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.