edubart / nelua-lang

Minimal, efficient, statically-typed and meta-programmable systems programming language heavily inspired by Lua, which compiles to C and native code.
https://nelua.io
MIT License
1.99k stars 64 forks source link

add __call metamethod support #256

Open codehz opened 5 months ago

codehz commented 5 months ago

WARNING: Please, read this note carefully before submitting a new pull request:

Nelua is open source, but not very open to contributions in the form of pull requests, if you would like something fixed or implemented in the core language try first submitting a bug report or opening a discussion instead of doing a PR. The authors prefer it this way, so that the ideal solution is always provided, without unwanted consequences on the project, thus keeping the quality of the software.

If you insist doing a PR, typically for a small bug fix, then follow these guidelines:

Motivation

Add basic __call metamethod support to nelua, align to lua's behavior

Code example

local Test = @record{value: number}

function Test:__call(a: number): number
  print "test"
  print(a)
  print(self)
  return self.value + a
end

local test: Test = {1}

-- test:__call(2)
test(2)