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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:15:05+00:00 2026-05-26T10:15:05+00:00

My C code consists of: /* ** lgamelib.c ** Game Library ** See Copyright

  • 0

My C code consists of:

/*
** lgamelib.c
** Game Library
** See Copyright Notice in lua.h
*/


#include <stdlib.h>
#include <math.h>

#define lgamelib_c
#define LUA_LIB

#include "lua.h"

#include "lauxlib.h"
#include "lualib.h"

static int game_workspace (lua_State *L) {
  lua_pushstring(L, "Workspace");
  return 1;
}

static int game_sound (lua_State *L) {

  return 1;
}


static const luaL_Reg gamelib[] = {
  {"Workspace", game_workspace},
  {"Sound",  game_sound},
  {NULL, NULL}
};


/*
** Open game library
*/
LUALIB_API int luaopen_game (lua_State *L) {
  luaL_register(L, LUA_GAMELIBNAME, gamelib);
  //lua_pushnumber(L, PI);
  //lua_setfield(L, -2, "pi");
  //lua_pushnumber(L, HUGE_VAL);
  //lua_setfield(L, -2, "huge");
  return 1;
}

After building the solution, for example, ‘print(game.Workspace())’ returns that ‘game’ is nil even though I’ve registered it. Any solutions? I’m completely stuck… I believe I need to include lgamelib.c somewhere but I don’t believe I need to.

  • 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-26T10:15:05+00:00Added an answer on May 26, 2026 at 10:15 am

    In the version of Lua I’m using (LuaInterface with lua5.1.1), I have to add new libraries to the lualibs[] array in linit.c. This array is called by the luaL_openlibs function, which will then call your luaopen_game function, or whichever library you are adding. I don’t know if this is the “correct” way to do add libraries, but it works for my code.

    Edit: After thinking about it, you don’t need to necissarily modify the linit.c file. After you create your lua state, you could manually call the library loader.

    lua_State  *L = lua_open();
    lua_pushcfunction(L, luaopen_game);
    lua_pushstring(L, "game");
    lua_call(L, 1, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My company has a common code library which consists of many class libary projects
I made a piece of code which consists in a dynamic library ( lib.c
I took some code here: Check if role consists of particular user in DB?
We are developing an application which consists of: a source code base given to
My job mostly consists of engineering analysis, but I find myself distributing code more
I'm writing test code to test a client-server application. The application under test consists
Currently, we are working on a C++ legacy code base, which consists of several
I've written some code that generates mazes for me. The maze consists of (n
I have written c# code which utilizes the HtmlAgilityPack library in order to scrape
The entire block of code consists of the following: CGSize layerSize = [webview sizeThatFits:CGSizeZero];

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.