8char / laux-compiler

The LAU project by Metamist (Alexander Arvidsson) has long been dead. This fork aims to breathe new life into the project and continue its development with some updates to syntax and functionality.
MIT License
11 stars 1 forks source link

parameter number mismatch in native lua #4

Closed avivi55 closed 1 year ago

avivi55 commented 1 year ago

Related to #3

When removing the istable function, I am prompted with

table: 0x55a3aaa48770
lua: tt.lua.lua:35: attempt to index a nil value (local 'yes')
stack traceback:
    tt.lua.lua:35: in field 'greetPerson'
    tt.lua.lua:63: in main chunk
    [C]: in ?

when looking at line 35 :

greetPerson = function(self, yes)

and the call (63) :

print(t.greetPerson("test"))

As seen in the definition the function takes two parameters and putting anything as a first parameter fixes the output.

print(t.greetPerson(0, "test"))
table: 0x559080175770
yes : test

The cause is probably that it works in gmod as a lot of gmod functions have a self argument as first parameter.

8char commented 1 year ago

I took a look at what you shared, and I think I can help you out. It seems like you're using the wrong operator to access your function.

In Lua, you can call a function using the colon syntax: t:greetPerson(player). The neat thing about the colon operator is that it automatically passes the object behind the : indexer, (in this case, t) as the first argument for you.

However, it looks like you're using the dot operator instead. You should switch to the colon operator. For example, if your function is defined as t.greetPerson = function(self, player) end, you would access it as t:greetPerson(player) (Which is the exact same as doing t.greetPerson(t, player)).

More documentation on OOP in LUA

From what you've described, it seems like the issue doesn't lie with the repository itself, but rather with how you're accessing the function. Give the colon operator a shot and let me know if the problem persists. If you need any further assistance, feel free to reopen the issue!

avivi55 commented 1 year ago

I am sorry for my poor knowledge, thank you for your explenation.