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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:40:34+00:00 2026-05-11T19:40:34+00:00

What is the best way to remove or omit a Lua standard library package?

  • 0

What is the best way to remove or omit a Lua standard library package? For example remove the os library functions in a particular environment. The project in question is building Lua from the source files so I can edit the source, although I would rather do it through the API if possible.

  • 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-11T19:40:34+00:00Added an answer on May 11, 2026 at 7:40 pm

    See the file luaconf.h in the source kit for easy access to most compile-time configuration such as the actual type used for lua_Number.

    See the file linit.c in the source kit for the list of core libraries that are loaded by calling luaL_openlibs().

    Common practice is to copy that file to your application’s source, and modify it to suit your needs, calling that copy’s luaL_openlibs() in place of the core version. If you are compiling Lua privately and not linking to one of the pre-built binaries of the library, then you can find a method to do the equivalent that suits your needs.

    Of course, you also don’t need to compile or link to the sources for any library (such as os, found in loslib.c) that you choose to leave out of luaL_openlibs().

    The only library that you probably can’t leave out completely is the base library that provides things like pairs(), ipairs(), pcall(), tostring(), and lots more that can be really inconvenient to do without. When porting to an environment where some of these are problematic, it is usually a good idea to look closely at its implementation in lbaselib.c and either trim features from it or reimplement them to suit your needs.

    Edit:

    Another approach to including a different list of libraries in the interpreter is to not call luaL_openlibs() at all. Although provided as a convenience, like all of the auxiliary library, luaL_openlibs() is not mandatory. Instead, explicitly open just the libraries you want.

    Chapter 5 of the reference manual talks about this:

    To have access to these libraries, the
    C host program should call the
    luaL_openlibs function, which opens
    all standard libraries. Alternatively,
    it can open them individually by
    calling luaopen_base (for the basic
    library), luaopen_package (for the
    package library), luaopen_string (for
    the string library), luaopen_table
    (for the table library), luaopen_math
    (for the mathematical library),
    luaopen_io (for the I/O library),
    luaopen_os (for the Operating System
    library), and luaopen_debug (for the
    debug library). These functions are
    declared in lualib.h and should not be
    called directly: you must call them
    like any other Lua C function, e.g.,
    by using lua_call.

    That last sentence is occasionally the source of trouble, since older versions of Lua did not have that restriction. Each of the individual module’s luaopen_xxx() functions follows the same protocol used by the require function. It should be passed a single argument: a string containing the name by which the module is known. The exception is the base module, which is passed an empty string because it has no actual name.

    Here’s a function that creates a new Lua state and opens only the base and package libraries:

    #include "lua.h"
    #include "lualib.h"
    #include "lauxlib.h"
    
    lua_State *CreateBasicLua() {
        lua_State *L;
    
        L = luaL_newstate();
        if (L) {
            lua_pushcfunction(L, luaopen_base);
            lua_pushstring(L, "");
            lua_call(L, 1, 0);
            lua_pushcfunction(L, luaopen_package);
            lua_pushstring(L, LUA_LOADLIBNAME);
            lua_call(L, 1, 0);
        }
        return L;
    }
    

    It returns the new lua_State on success, or NULL on failure.

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

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is a W3C XQuery test suite that at least… May 12, 2026 at 12:22 am
  • Editorial Team
    Editorial Team added an answer Call sendto without calling bind first, the socket will be… May 12, 2026 at 12:22 am
  • Editorial Team
    Editorial Team added an answer You have to see if the site in question supports… May 12, 2026 at 12:22 am

Related Questions

What is the best way to remove all the special characters from a string
I recently noticed that my installer (VS 2008) does not remove the DLLs during
Say I have the following style of lines in a text file: 12 34
I have a rails application where I would like to use both memcached and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.