Example #1
0
 int open_package()
 {
     if (L)
     {
         luaopen_package(L);
         return 0;
     }
     return -1;
 }
Example #2
0
bool loadModules()
{
    loadEmbeddedModules(L);

    ChangeDir cd;
    if (!cd.changeDir(L"modules"))
    {
        lua_register(L, "require", require_stub);
        return false;
    }

    tstring path(cd.getCurrentDir());
    path.append(L"\\modules\\?.dll");
    luaopen_package(L);
    lua_pushstring(L, "path");
    lua_pushstring(L, "");
    lua_settable(L, -3);
    lua_pushstring(L, "cpath");
    lua_pushstring(L, TW2A(path.c_str()));
    lua_settable(L, -3);
    lua_setglobal(L, "package");
    lua_pop(L, 1);

    std::vector<tstring> files;
    {
        WIN32_FIND_DATA fd;
        memset(&fd, 0, sizeof(WIN32_FIND_DATA));
        HANDLE file = FindFirstFile(L"*.*", &fd);
        if (file != INVALID_HANDLE_VALUE)
        {
            do
            {
                if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
                {
                    if (Module::isModule(fd.cFileName))
                        files.push_back(fd.cFileName);
                }
            } while (::FindNextFile(file, &fd));
            ::FindClose(file);
        }
    }

    for (int j = 0, je = files.size(); j < je; ++j)
    {
        TW2A w2a(files[j].c_str());
        if (luaL_dofile(L, w2a))
        {
            tstring error(L"Ошибка при загрузке модуля: '");
            error.append(files[j]);
            error.append(L"' - ");
            error.append(luaT_towstring(L, -1));
            pluginOut(error.c_str());
        }
    }
    return true;
}
Example #3
0
LuaInterfaceBase::LuaInterfaceBase(): lua(kaguya::NoLoadLib())
{
    luaopen_base(lua.state());
    luaopen_package(lua.state());
    luaopen_string(lua.state());
    luaopen_table(lua.state());
    luaopen_math(lua.state());

    Register(lua);
}
Example #4
0
File: interp.c Project: sebcat/birk
interp_t *interp_new(int flags, int ipcfd) {
	interp_t *interp = NULL;
	lua_State *L = NULL;
	static const luaL_Reg ipcfuncs[] = {
		{"ready", bipc_ready},
		{"connect", bipc_connect},
		{NULL, NULL},
	};

	L = luaL_newstate();
	if (L == NULL) {
		return NULL;
	}

	luaopen_base(L);
	luaopen_coroutine(L);
	luaopen_table(L);
	luaopen_string(L);
#if (LUA_VERSION_NUM >= 503)
	luaopen_utf8(L);
#endif
	luaopen_bit32(L);
	luaopen_math(L);
	luaopen_debug(L);
	luaopen_package(L);
	/* not opened: io, os */

	/* create a userdata object that represents the interpreter */
	interp = (interp_t*)lua_newuserdata(L, sizeof(interp_t));
	if (interp == NULL) {
		lua_close(L);
		return NULL;
	}

	memset(interp, 0, sizeof(interp_t));
	interp->ipcfd = ipcfd;
	interp->L = L;

	/* Build a metatable with the methods for our userdata object.
	 * Assign the userdata object to BIRK_IPCNAME */
	luaL_newmetatable(L, BIRK_IPCNAME);
	lua_pushvalue(L, -1);
	lua_setfield(L, -2, "__index");
	luaL_setfuncs(L, ipcfuncs, 0);
	lua_setmetatable(L, -2);
	lua_setglobal(L, BIRK_IPCNAME);

	if ((flags & INTERPF_LOADBIRK) && interp_load(interp, "birk") != BIRK_OK) {
		/* error message is set, caller should check it on return */
		return interp;
	}

	return interp;
}
Example #5
0
bool LuaWrapper::openPackage()		{ luaopen_package(m_luaState);		return true; }