daokoder / dao-modules

Dao Standard Modules
http://daovm.net
12 stars 5 forks source link

os/fs module behaves weird #3

Closed dumblob closed 11 years ago

dumblob commented 11 years ago

I'm just curious why the fs module from the os directory behaves like is shown at the bottom. I assume, the declarations in the fsnodeMeths[] array in dao_fs.c with self as a the first argument are methods and the rest are module-specific routines accessible using module_name.module_specific_routine() syntax.

1$ dao -e "load fs; x=fsnode('/')"
= fsnode[0x1764af0]
1$ dao -e "load fs; x=fs.fsnode('/')"
[[ERROR]] in file "command line codes":
  At line 1 : Invalid statement --- " fs ";
  At line 1 : Invalid expression --- " fs.fsnode('/') ";
  At line 1 : Symbol not defined --- " fs ";
1$ dao -e "load fs; x=cwd()"
[[ERROR]] in file "command line codes":
  At line 1 : Invalid statement --- " cwd ";
  At line 1 : Invalid expression --- " cwd() ";
  At line 1 : Symbol not defined --- " cwd ";
1$ dao -e "load fs; x=fs.cwd()"
[[ERROR]] in file "command line codes":
  At line 1 : Invalid statement --- " fs ";
  At line 1 : Invalid expression --- " fs.cwd() ";
  At line 1 : Symbol not defined --- " fs ";

with module "renaming":

1$ dao -e "load fs as fs; x=fsnode('/')"
[[ERROR]] in file "command line codes":
  At line 1 : Invalid statement --- " fsnode ";
  At line 1 : Invalid expression --- " fsnode('/') ";
  At line 1 : Symbol not defined --- " fsnode ";
1$ dao -e "load fs as fs; x=fs.fsnode('/')"
= fsnode[0x22503b0]
1$ dao -e "load fs as fs; x=cwd()"
[[ERROR]] in file "command line codes":
  At line 1 : Invalid statement --- " cwd ";
  At line 1 : Invalid expression --- " cwd() ";
  At line 1 : Symbol not defined --- " cwd ";
1$ dao -e "load fs as fs; x=fs.cwd()"
[[ERROR]] in file "command line codes":
  At line 0 : Invalid function definition --- " __main__() ";
  At line 1 : Invalid virtual machine instruction --- " GETF:0,0,1 ";
  At line 1 : Member not exist --- " fs.cwd for namespace ";
daokoder commented 11 years ago

Actually, cwd() is a static method of fsnode, so it can be called by:

    fsnode::cwd()
    fsnode.cwd()

If you use "load fs as fs", simply prefix the above codes with "fs::" or "fs.".

Of course, cwd() can be implemented module specific method, but here, it seems more natural to have it as static method of fsnode.

dumblob commented 11 years ago

Thank you, my fault, I'm ashamed.