lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


so..I find something in loadlib.c 

this is 4 loader: 
static const lua_CFunction loaders[] =
  {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};

I suggest add a loader for current path like:

static int loader_current (lua_State *L) {
  const char *filename;
  const char *path = get_current_path(L);
  const char *name = luaL_checkstring(L, 1);
  char pathname[256];
  strcpy(pathname,path);
  filename = strcat(pathname,name);
  if (readable(filename))
  {
    push_current_path(L,filename);
    if (luaL_loadfile(L, filename) != 0)
      loaderror(L, filename);
    pop_current_path(L);
  }
  return 1;
}

but, so shy, I can not finish get_current_path, push_current_path, pop_current_path , there are so many details I don't know about lua

----- Original Message ----- 
From: "mos" <mmosquito@163.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Friday, June 25, 2010 3:06 PM
Subject: Re: require vs dofile (lua 5.1.4 windows)


>I should make a summary:
> require a  .lua file not use ".lua" because require treat  '.' as '\\' 
> when require "a.lua"
> the lua will look for "a\lua.lua"
> so when use relative path "..\" like require "..\\a\\a" you will never get right path 
> the lua will look for \\a\a.lua still in the same dir b
> 
> is that a bug ? 
> 1. It should handle "..", if the prefix is ".." not treat as \\\\
> 2. (suggestion) if the postfix  is ".lua" not treat '.' as '\\'
> 
> and I wish dofile will solved this, but in the a.lua 
> will also require another file like 'c'
> a 
>   a.lua
>   c.lua
> b 
>   b.lua
> when use dofile in b.lua like dofile("..\\a\\a.lua") will cause a error can not find c.lua
> 
> So I hope solved it.
> 
> 
> ----- Original Message ----- 
> From: "mos" <mmosquito@163.com>
> To: "Lua list" <lua@bazar2.conectiva.com.br>
> Sent: Thursday, June 24, 2010 2:13 PM
> Subject: require vs dofile (lua 5.1.4 windows)
> 
> 
>> Hi!
>>    there are 2 files in 2 fold like:
>> a 
>>  a.lua
>> b 
>>  b.lua
>> 
>> the b.lua use
>>  require "..\\a\\a.lua"
>> will get a error can not find a.lua
>> 
>> but use
>>  dofile("..\\a\\a.lua")
>> will ok
>> 
>> I don't konw why.
>> 
>> Best Regard
>> yujiang
>>