C++ & Lua registering custom lua library at runtime

  c++, lua, luajit, qt

I’m currently trying to implement LUA into my CPP program however I am having the following issue: I have a library in lua lets say lib.lua that I’d like to be ran into runtime so that other lua scripts can access it however I’m having issues with that here’s my code:

    /* initialize Lua */
    L = luaL_newstate();

    /* load Lua base libraries */

    /* load the script */
    luaL_loadfile(L, "d://Game.Helper/Lua/libs/loader.lua");

    lua_call(L, 0, 0);
    // clean it up

The loader.lua contains information on where to load my libraries from :

package.path = 'D:/Game.Helper/Lua/libs/?.lua;'..package.path
local class = require 'middleclass'

After doing this I’m calling a test file using lua_dofile(test.lua) however in my test file I get the error message that global class is ‘nil’ I’m guessing because my library is not being added into runtime? this is my test.lua:

function Test::initialize()

local Test = class('Test')

Any help is greatly appreciated, thank you!

Source: Windows Questions C++