Anubhav Posted June 4, 2016 Share Posted June 4, 2016 To your knowledge.. @Anubhav, C++ has public, private and protected visibility modes. Ensuring safety among privacy. MTA was written in C++. GTA was written in C++/DirectX. GTA V was written in C++/OpenGL. So.. if MTA makes C++ coordination dll. then we can start MTA 5 or MTA 4 or something like that for GTA 4 and GTA V. I'm not a pro C++ developer, but clearly you got some things wrong there. DirectX is nothing more than Microsoft Windows' 3D graphics library, so it is not a language by itself, to start with. GTA V, on the other hand, uses DirectX, not OpenGL (have you ever seen the DirectX version option that GTA V has in its graphics settings?). And I have never heard the words "coordination dll". GTA: SA, GTA IV and GTA V are very different games, and making a mod like MTA: SA work with any of them is a very difficult task, because although MTA tries to build its own engine on top of GTA: SA, it still depends on assembly hooks and memory manipulation of the game itself. And, as you can probably conclude, GTA: SA executable and memory has (almost) nothing in common with GTA IV or GTA V ones. Back to the topic, I think that Lua is fine to use as a MTA: SA scripting language. Sure, it is not the fastest and most known thing out there, but it is designed with embedding in mind, it has a good learning curve, it is well documented, it is powerful and, most importantly, safe. C++, on the other hand, is lower-level, and things like memory manipulation are difficult to sandbox without reducing functionality. So, in the end, C++ doesn't simply cut it. That was some nice information.. Thanks. Also if C++ was better, why wouldn't MTA Team choose C++ only? Link to comment
Deepu Posted June 24, 2016 Author Share Posted June 24, 2016 oh well.. sorry Alex.. I thought GTA V was written in OpenGL library.. anyways.. back to the topic.. Uhmm.. alright then.. Lua has good learning curve and even "starters" in coding can use lua. But C++ is lightning fast.. I mean.. the memory bank management in C++ is so fast! not a single lag would be caused due to having too many variables in a single script but I have definitely noticed some scripts that have a lot of variables (1000+ lines of lua code) will lag like hell! Link to comment
Discord Moderators AlexTMjugador Posted June 24, 2016 Discord Moderators Share Posted June 24, 2016 That is actually true. Lua will always be slower than a language that compiles directly to asssembly code, just by definition. The virtual machine adds some overload, even if it is negible. However, the vast majority of the times Lua performance is enough to script things for MTA. Custom encryption, compression, hashing or similar algorithms written in pure Lua are orders of magnitude slower (and perhaps memory demanding) than their C++ counterparts, but it is possible to workaround that to a certain extent. For example, you can use coroutines to alleviate and distribute the CPU usage, and do expensive operations only when they are not much of a hassle for the user, so even if it is slow it won't actually "lag". I bet that entire gamemodes like race have more than 1000 lines of code, while they are smooth to play. The real problem here is that most people that makes scripts is happy if they just work, thinking like "if it ain't broke, don't fix it". They just don't care if they could save some memory by destroying textures when the element streams out, save CPU usage by using pairs instead of ipairs when order is unimportant and things like that. And even if more performance is needed for the language, LuaJIT is a pretty convincing Lua-alike solution which is almost like C in terms of performance. It sacrifices portability and some things, but the result is basically a faster Lua. You can compare C, Lua, LuaJIT and Java in articles like this one, and although Lua may seem slow, take this: 1 second is like no time if done correctly, and Lua can perform better in other situations. Link to comment
Bonsai Posted June 24, 2016 Share Posted June 24, 2016 I can't believe this topic is still active. This is MOST obviously never gonna happen. Link to comment
DiSaMe Posted July 3, 2016 Share Posted July 3, 2016 @Anubhav I didn't say that Lua has to be stopped. I said that Lua is not flexible for OOP else people would have made minecraft with lua.. right? C++ is flexible because it has its own class support and object oriented systems development resources. If yu know crystalMV then.. even he likes using C or C++ because its more easier and more simpler to learn and to program. so we all can do it with C++. Excuse me, but you're kind of putting words in my mouth, because that's not what I've said. Actually, Lua is my favorite language. I'm making a game engine in C and it's scriptable in Lua. That's because it's inspired by MTA. OOP is one of the aspects where I can see the beauty of Lua's simplicity. Instead of providing us with a built-in class system, it allows us to control the behavior of individual tables, which enables us to make classes ourselves. Not sure where C fits into this OOP thing, since it doesn't have any syntax for OOP at all. I do write OOP in C using opaque pointers and functions that receive those pointers as arguments. That's what I pretty much got used to doing in C, but that's not as convenient as OOP in Lua. Lua does allow you to make variables only accessible via particular objects. Consider this example: function Person(name) local self = {} local person_name = name function self.getName() return person_name end return self end Calling 'Person' function will create and return a table (an 'object'), and the value passed as the first argument can only be read by calling getName field of this table, and it cannot be accessed from outside the 'Person' function. C/C++ easier, really? Easier how? I mean... Strong typing, pointers, all that stuff... How is that easier than Lua? Speaking of performance, one of the reasons C/C++ are so fast is because there are many things that have undefined behavior. Which allows the optimizer to pretend that those situations will not occur, making more assumptions about execution of code during the compilation. Undefined behavior would totally kill security in MTA, because the servers can execute code on clients' computers. To avoid this problem, all behavior needs to be defined, and such implementation of C/C++ wouldn't be that fast. Though it would probably still be faster than Lua can be made, because Lua is more dynamic, the point is, what makes C/C++ fast, the same thing makes the language unsuitable for software that lets the servers execute code on clients' computers. Link to comment
Piorun Posted July 4, 2016 Share Posted July 4, 2016 Show me how to mix private and public variables and we will be in da house. Link to comment
Discord Moderators AlexTMjugador Posted July 4, 2016 Discord Moderators Share Posted July 4, 2016 You don't have to think much to see how public variables can be integrated into Lua OOP: people_address = {} function Person(name, address) local self = {} local person_name = name people_address[self] = address function self.getName() return person_name end function self.getAddress() return people_address[self] end return self end That will give you a public variable per instance just by indexing the people_address table accordingly. Link to comment
Piorun Posted July 6, 2016 Share Posted July 6, 2016 You mean by your code I can do something like local p = Person("Piorun","test"); outputChatBox(p.address); and it will work or I should call address in other way? Link to comment
Discord Moderators AlexTMjugador Posted July 6, 2016 Discord Moderators Share Posted July 6, 2016 The code I posted is not a public variable in a proper OOP way, so sorry for that. It is wonderful how Lua lets you do what you want even if it's something "new", don't you think? That syntax you posted won't work, but with this code it will: function Person(name, address) local self = {} local person_name = name self.address = address function self.getName() return person_name end function self.getAddress() return self.address end return self end That is the proper way to have public variables in Lua OOP: you can get them by using either object.variable or object:getVariable (in this case, object.address and object:getAddress). Link to comment
Recommended Posts