Wrong information on the Wiki regarding the panel ListView
6 replies, posted
Hi all.
As I printed the arguments yesterday I noticed that the first is a panel and second is a number, when calling
[url]http://wiki.garrysmod.com/page/DListView/OnRowSelected[/url]
[code]
ListView.OnRowSelected = function(pnPanel, nRow)
trackasmlib.Print(pnPanel,"OnRowSelected > Index")
trackasmlib.Print(nRow,"OnRowSelected > Row")
end
[/code]
Varaible "nRow" was indeed 1 instead of panel ( when the 1-st row was selected ).
Should it be that way or ...??
The wiki does have some mistakes. If you spot one, and know how to correct it, feel free to do so! It's a wiki, that means that anyone anywhere can edit it.
If you don't know how to correct it, then yeah, just ask on the forums like you just did :)
It's being called as a metamethod, meaning that the object itself is passed to the function.
If you create the function like this: function DListView:OnRowSelected(rowIndex, row) end, the first argument will not be a panel since the panel is now self inside the function.
You can create the function like you did, though it will have an extra argument: panel, rowIndex, row.
[QUOTE=ms333;47079786]It's being called as a metamethod, meaning that the object itself is passed to the function.
If you create the function like this: function DListView:OnRowSelected(rowIndex, row) end, the first argument will not be a panel since the panel is now self inside the function.
You can create the function like you did, though it will have an extra argument: panel, rowIndex, row.[/QUOTE]
Aren't then we supposed to override using DOT notation instead of : ? I mean it's a field in a table in both cases .. correct me if I am wrong.
[editline]5th February 2015[/editline]
[QUOTE=Neat-Nit;47079754]The wiki does have some mistakes. If you spot one, and know how to correct it, feel free to do so! It's a wiki, that means that anyone anywhere can edit it.
If you don't know how to correct it, then yeah, just ask on the forums like you just did :)[/QUOTE]
Nope, I cannot correct anything, I don't have rights, So I write at the function's comments below.
Like I did here for example: [url]http://wiki.garrysmod.com/page/Vector/AngleEx[/url]
Better be the thing down below then ...
ListView.OnRowSelected = function(pnSelf, nRow, pnVal)
Wiki is not wrong there. All methods ( methods are called by doing self:Method( ... ) ) have self argument that becomes the first argument if you call it like a normal function: self.Method( self, ... ).
Read up about implicit/explicit parameter passing for languages like C++/Java.
PIL has more specifics if you're still confused: [URL]http://www.lua.org/pil/16.html[/URL]
It's just simple syntatic sugar.
[QUOTE=Robotboy655;47080160]Wiki is not wrong there. All methods ( methods are called by doing self:Method( ... ) ) have self argument that becomes the first argument if you call it like a normal function: self.Method( self, ... ).[/QUOTE]
Lua manual common sense ;)
Sorry, you need to Log In to post a reply to this thread.