🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

LUA - . rather than :

Started by
4 comments, last by FearedPixel 20 years, 6 months ago
Surely I am not the only one who thinks its stupid to use '':'' for method calls rather than just ''.'' ? Does anyone know what would need to be changed in the LUA source-code to get this effect? (I''m assuming it can''t be such a large task?)
Advertisement
Every language has different syntax. Suck it up.
quote: Original post by Anonymous Poster
Every language has different syntax. Suck it up.


Despite how stupid he sounds, I agree.



Check out my Forum
My First Space Art (Ever)
My Second Space Art (Ever)
My upcoming space mod for Battlefield: 1942.

Status: 25% Me and a friend are working on it, we are pretty much ready to release in game screenshots.
The Untitled RPG - |||||||||| 40%Free Music for your gamesOriginal post by capn_midnight 23yrold, is your ass burning from all the kissing it is recieving?
quote: Original post by FearedPixel
Surely I am not the only one who thinks its stupid to use '':'' for method calls rather than just ''.'' ? Does anyone know what would need to be changed in the LUA source-code to get this effect? (I''m assuming it can''t be such a large task?)

They perform different actions. To change it would require other changes to the syntax, and would be quite a lot of work. There would have to be some way for the compiler to work out which calls are meant to be method calls, and which calls aren''t (and the only way you could work that out would involve other changes to the syntax).
The way it is at the moment is very flexible, and the syntax is perfectly understandable and reasonable if you read the docs.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
You are perfectly free to use . instead of :, as long as you go ahead and pass self explicitly if required. It might seem a little silly, but it has to do with the way objects are handled in a dynamically typed language. All elements of a table, functional or otherwise, are at base the same basic object type, and so the syntax for referencing an object is the same across objects. The .< whatever > syntax references an element of a Lua table named whatever, whether it is a function object or chunk, a number, a string, another table, etc...

The : extends the behavior of . by adding class-like functionality to function calls. You don''t have to use it, as it is really just a short-cut for implementing a self parameter (sort of like an implicit this) as the first parameter passed to the function object. Just remember that a function object that is declared using the : operator expects that self parameter, so if you subsequently call it using . you will need to explicitly pass self.

The declaration...

function MyTable:MyFunction(MyParameter)
--Do some stuff
end

...is exactly equivalent to

function MyTable.MyFunction(self, MyParameter)
-- Do some stuff
end

You can call either function this way...

MyTable:MyFunction(SomeParameter)

... or this way...

MyTable.MyFunction(MyTable, SomeParameter)

But if you call them this way...

MyTable.MyFunction(SomeParameter)

... then you will get an error due to being short by one parameter.

I wouldn''t go mucking around changing the behavior of the . operator in source if I were you, as it could have far-ranging repercussions on the behavior of . for other object types.


Josh
vertexnormal AT linuxmail DOT org

Check out Golem: Lands of Shadow, an isometrically rendered hack-and-slash inspired equally by Nethack and Diablo.
quote: Original post by Nypyren
Lnguage coder: "oh, I think I''ll change this . to a :! it''s SO different that way and makes 20x more sense and people won''t think I was ripping any other languages off."

This is the reason why I don''t learn your fucking pansy-ass language, dipweed.

No offense to LUA, or PHP, or Python, or lisp or any of those other languages.

[edited by - Nypyren on January 5, 2004 6:36:43 AM]


LUA helped me with a scripting system an a project i worked on last year. Yes it''s not a great language but it is designed to work on another one. no offence, but thats a stupid comment.

in regards to the topic just think, at least its a ":" as appose to an "#" or something.

This topic is closed to new replies.

Advertisement