ThakeeNathees / pocketlang

A lightweight, fast embeddable scripting language.
https://thakeenathees.github.io/pocketlang/
MIT License
1.52k stars 80 forks source link

access class and instance attribs by '_attr' #276

Closed khchen closed 2 years ago

khchen commented 2 years ago

Allow following code:

class Foo
  def []=(key, value)
    self._attr[key] = value
  end
end

f = Foo()
f["a" + "b"] = 123

assert(f.ab == 123)

Moreover, maybe @getter and @setter can be renamed to _getter and _setter. Don't need to limit them be used in native module only.

class Foo
  def _getter(key)
    # do someing...
    return self._attr[key]
  end

  def _setter(key, value)
    # do someing...
    self._attr[key] = value
  end
end
khchen commented 2 years ago

close temporary