of     2   
chevron_rightchevron_rightchevron_right

ked2000
#138875045Tuesday, July 01, 2014 5:26 PM GMT

I have a file that is inside of a folder called 'libs'. I am trying to access the _main file using require. How can I do this? I have tried: require "libs/_main" and require "libs\_main"
ked2000
#138889913Tuesday, July 01, 2014 7:46 PM GMT

Anyone?
ked2000
#138898117Tuesday, July 01, 2014 9:00 PM GMT

Help?
ked2000
#138902958Tuesday, July 01, 2014 9:42 PM GMT

I am sure there is someone out there who knows.
vlekje513
#138903563Tuesday, July 01, 2014 9:47 PM GMT

Eh, wut.
DataStore
#138903608Tuesday, July 01, 2014 9:47 PM GMT

The main reason people aren't responding, or so I'd assume, is because you're not being very clear. If this is regarding RBX.Lua's require function, then you'd use it like (but would differ to what you need): local Module = require(script.Parent.libs["_main"])
warspyking
#138903911Tuesday, July 01, 2014 9:50 PM GMT

He wants to load a .lua file from his library. You could do this using loadfile as far as I know.
ked2000
#138903920Tuesday, July 01, 2014 9:50 PM GMT

Ok, sorry I didn't explain this earlier. I am writting in Lua, not ROBLOX-styled Lua. Meaning, Lua's require function differs from ROBLOX's require function.
ked2000
#138904195Tuesday, July 01, 2014 9:52 PM GMT

@warspyking Will I have to give the absolute path of the file or just 'libs/_main.lua'. Besides, shouldn't Lua have this kind of capability with require?
warspyking
#138905931Tuesday, July 01, 2014 10:06 PM GMT

Use load; f = loadfile("C:/file.lua") f() Works like that (the wiki says)
ked2000
#138907291Tuesday, July 01, 2014 10:16 PM GMT

Tried this: local user = "#####" --Just for show, my actually name is in 'user' loadfile("C:/Users/"..user.."/Desktop/Folders/Programming/Lua/Projects/My Framework/_main.lua") Still doesn't work.
ked2000
#138907691Tuesday, July 01, 2014 10:19 PM GMT

Even after I put the (), it doesn't work.
warspyking
#138907838Tuesday, July 01, 2014 10:20 PM GMT

F = loadfile("C:/Users/%username%/Desktop/Folders/Programming/Lua/Projects/My Framework/_main.lua") F() %username% automatically corrects to the username.
ked2000
#138908361Tuesday, July 01, 2014 10:24 PM GMT

Thanks, but it still doesn't work.
warspyking
#138908556Tuesday, July 01, 2014 10:25 PM GMT

Try getting rid of ".lua"
ked2000
#138908745Tuesday, July 01, 2014 10:27 PM GMT

Yep, did that and it didn't work still. Perhaps I should just move it into the same directory as main.lua?
warspyking
#138909606Tuesday, July 01, 2014 10:33 PM GMT

I did some research. Try this; F = assert(loadfile("C:/Users/%username%/Desktop/Folders/Programming/Lua/Projects/My Framework/_main.lua")) F()
ked2000
#138917556Tuesday, July 01, 2014 11:38 PM GMT

After looking around on stackoverflow I came up with this: package.path = package.path .. ";C:/Users/#######/Desktop/Folders/Programming/Lua/Projects/MyFramework/?.lua" require "_main"
warspyking
#138917955Tuesday, July 01, 2014 11:41 PM GMT

Did you try the one I showed you with assert?
ked2000
#138918728Tuesday, July 01, 2014 11:48 PM GMT

Yes, but it didn't work. I will show you the script I am working on. I did not make this script, I edited it. It was made by TheLuaWeaver in his framework(OO). ---------------------------------------- package.path = package.path .. ";C:/Users/#######/Desktop/Folders/Programming/Lua/Projects/MyFramework/?.lua" require "main" ---------------------------------------------------------------------- package "Classes" --Define as a package ---------------------------------------------------------------------- addException("ClassNotFound", "Class ['~1~'] was not located") --Add important exceptions ---------------------------------------------------------------------- -- @Public ---------------------------------------------------------------------- function class(arg0) return function(arg1) if (type(arg1) == "string") then return function(arg2) Private.addClass(arg0, arg1, arg2) end else Private.addClass(arg0, "base", arg2) end end end ---------------------------------------------------------------------- -- @Private ---------------------------------------------------------------------- local Classes = { ["base"] = { mt = { __toString = function(self) return "Class ['"..self.ClassName.."']"; end; }; }; } local Private = {} Private.addClass = function(name, extends, args) if (Classes[extends]) then args = Private.inherit(args, Classes[extends]) else throwException("ClassNotFound", name) end Classes[name] = args; args["ClassName"] = name setmetatable(Private.inherit({}, args), { __call = function() local tab = Private.inherit({}, Classes[name]) setmetatable(tab, tab.mt) return tab end; } ) end Private.inherit = function(tab0, tab1) for i, v in pairs(tab1) do tab0[i] = tab0[i] or (type(v) == "table" and Private.inherit({}, v) or v) end return tab0 end os.execute("pause") --To check if it passes without errors.
warspyking
#138921215Wednesday, July 02, 2014 12:12 AM GMT

package.path = package.path .. "C:/Users/%username%/Desktop/Folders/Programming/Lua/Projects/MyFramework/_main.lua"
warspyking
#138921420Wednesday, July 02, 2014 12:14 AM GMT

If it STILL don't work, try using dofile.
ked2000
#138984958Wednesday, July 02, 2014 3:38 PM GMT

No luck.
warspyking
#138993626Wednesday, July 02, 2014 5:12 PM GMT

Did you attempt to use dofile?
warspyking
#138994166Wednesday, July 02, 2014 5:17 PM GMT

If you still want to attempt require, here's a good link; http://www.lua.org/pil/8.1.html

    of     2   
chevron_rightchevron_rightchevron_right