|
|
||
|
On 13/06/16 01:30 AM, Sean Conner wrote:
It was thus said that the Great Soni L. once stated:On 12/06/16 09:57 PM, Sean Conner wrote:local mt_reqpath = {} function my_reqpath:__index(key) table.insert(self.path,key) return self end function my_reqpath:__call(...) table.insert(self.path,1,self.base) local path = table.concat(self.path,".") self.path = {} return require(path) end function reqpath(path) return setmetatable( { base = path , path = {} }, my_reqpath ) endDoesn't seem like this would work local soniex2 = reqpath"io.github.soniex2" local a = soniex2.a() local bpath = soniex2.b local c = bpath.c() local b = bpath() -- ??? what happens here?Did you try it? What should happen there?
Didn't try it, but based on the code, it should act like this:local soniex2 = reqpath"io.github.soniex2" --> local t1 = {base="io.github.soniex2", path={}}
--> local soniex2 = t1
local a = soniex2.a() --> t1 =
{base="io.github.soniex2", path={"a"}}
--> local a = t1() -->
require("io.github.soniex2.a")
--> t1 =
{base="io.github.soniex2", path={}}
local bpath = soniex2.b --> t1 =
{base="io.github.soniex2", path={"b"}}
--> local bpath = t1 --
bpath is just an alias for t1
local c = bpath.c() --> t1 =
{base="io.github.soniex2", path={"b", "c"}}
--> local c = t1() -->
require("io.github.soniex2.b.c")
--> t1 =
{base="io.github.soniex2", path={}} -- remember that the call clears
self.path?
local b = bpath() --> local b = t1() -->
require("io.github.soniex2") -- oops! should be "io.github.soniex2.b"
Why are you? :PI have no idea ... -spc (Must be a slow Sunday ... )
-- Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.