GithubHelp home page GithubHelp logo

__newindex about nelua-lang HOT 2 OPEN

IcedQuinn avatar IcedQuinn commented on August 10, 2024
__newindex

from nelua-lang.

Comments (2)

edubart avatar edubart commented on August 10, 2024

Support for __newindex has yet to be added, when it's added this error should be fixed. But this I could make this at least a compile error for now.

You can use __atindex to overcome this, however you have to integer a reference, so I understand that this is not exact replacement for __newindex and __index, but one advantage is that you need to implement only one method, here is an example with __atindex:

local Farce = @record{x: integer}
function Farce:__atindex(x: auto): *integer
  return &self.x
end

local bleb: Farce
print(bleb["snert"])
bleb["snert"] = 32

from nelua-lang.

IcedQuinn avatar IcedQuinn commented on August 10, 2024

But this I could make this at least a compile error for now.

Yes. It definitely should not emit invalid C lol.

__atindex

I don't understand what is going on with this one. Its returning the reference to the call site which is then modifying it?

In Nim all of our operators are just syntactic sugar. []= has a signature []=(key: type; new_value: type) and it seems like Lua does something similar with the assignment syntax becoming a call to __newindex. But I'm not familiar with this codebase so I don't know how difficult patching it in would be.

from nelua-lang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.