• Class Based Lua
    50 replies, posted
[QUOTE=Anthoni_c;25622407]I don't think it is a real problem. Yet I do think that it would be a much more nice format. Instead of having cl_init.lua, init.lua, shared.lua, and lots of other files for my gamemode I would just have one gamerules class like in the C++ Source Engine Code. Player extensions would actually extend the player class like C_HL2MP_Player extends from C_HL2_Player which extends from CBaseMultiplayerPlayer in C++. Entities would just extend the CBaseAnimating entity but of course given proxy classes to extend them like is done with the Base gamemode in gmod already. [lua] class "DeathmatchGamerules" ( "BaseGamerules" ) DeathmatchGamerules.PrintName = "Deathmatch" DeathmatchGamerules.Author = "Abstract" function DeathmatchGamerules:Initialize() //Do Stuff end function DeathmatchGamerules:Think() end function DeathmatchGamerules:DeathNotice( victim, dmg_info) end [/lua] garrysmod/deathmatch/classes/dm_gamerules.lua garrysmod/deathmatch/classes/dm_player.lua garrysmod/deathmatch/classes/dm_assault_rifle.lua[/QUOTE] It's really more a matter of preference. It's like adding the formats from languages you learned to the next one you work with. It's just silly is all. What you're saying it having a standard class syntax would make Lua easier to work with. Tables are far more versatile than classes, and their syntax is much more flexible. I know people who make a preprocessor which will convert their classes to tables, but that's due to a very strong background in C++ and not wanting to make the shift over to tables. I see where you're coming from, but it's simply not true to say having classes would make Lua easier for the general userbase.
Yes, but these "classes" are really just Lua tables in the first place, so they would still retain their versatility, but I guess it does just boil down to preference.
If we wanted Lua to be exactly like another language, we wouldn't be using Lua, now would we? :3
Well what I would prefer is Dynamic like Lua, but the same Syntax as C++. Lua at the moment is the best option for this because it has alternatives to pointers, tables are very nice, and the syntax is not bad. As Dr Magnusson pointed out this can be done already in Lua. So we are not actually changing anything, but the coding style. ;) Also, I know about the Scripting Language Squirrel, but I am not about to ask Garry to rip out Lua and replace it. Lol.
[QUOTE=Gbps;25626089]If we wanted Lua to be exactly like another language, we wouldn't be using Lua, now would we? :3[/QUOTE] This is why I absolutely hate C syntax in Lua.
[QUOTE=amcwatters;25626849]This is why I absolutely hate C syntax in Lua.[/QUOTE] I like to think that's because garry once considered [url=http://www.somedude.net/gamemonkey/]GameMonkey[/url] instead of Lua for scripting, which has a more C-like syntax, with classes and stuff. Lua with C-syntax is pretty close to GM.
Isn't JavaScript a lot like Lua? He should've used [url=http://code.google.com/p/v8/]v8[/url], but that was released some time after gmod I think.
Javascript is full of design flaws, it's horrible in a lot of ways.
Well maybe someone should make a module to include Javascript into gmod? Just an idea ^^
[QUOTE=dingusnin;25634550]Well maybe someone should make a module to include Javascript into gmod? Just an idea ^^[/QUOTE] I think someone made an XML parser a while ago (I could be wrong, though), but I don't see why making a javascript interpreter would be impossible. It would probably be a pain to make it, and kind of pointless since Lua's syntax is so similar.
You could actually implement V8 really easily using a Binary module, and binding it to a Lua Function. Yet doing that just to use JS seems a bit much, and rather pointless.
[QUOTE=aualin;25633790]Javascript is full of design flaws, it's horrible in a lot of ways.[/QUOTE] I have no idea. I just looked at the syntax and it looked a lot like lua, but with C style syntax. I know Garry mentioned implementing it or something in one of his blog posts ages ago. What are the design flaws? [editline]25th October 2010[/editline] Anyway, if the reason you want JavaScript in gmod is just because of the syntax then deal with it. Lua's syntax isn't THAT bad and it's not like you can't get used to it. Maybe "!" instead of "not" is shorter and simpler, but I prefer it more verbal anyway (if that's the word for it) At least it's not like those other languages where you reverse keywords. That shit looks retarded. [lua]if var == true then print("true") fi do -- new scope od function HelloWorld() print("exaggerating") noitcnuf[/lua]
The only thing I dislike about lua is ~= because it's awkward to type out the ~ (inb4 change layout) But then again it's equally awkward to type out || in c++:rolleyes:
Yeah I don't like typing ~= either. It's probably only like that for us Scandinavians though. We have to double press a button near enter, then it makes the symbol twice like so ~~ and then we need to remove one and then we can make =
[QUOTE=CapsAdmin;25635123][lua]if var == true then print("true") fi do -- new scope od function HelloWorld() print("exaggerating") noitcnuf[/lua][/QUOTE] I have never heard of such a language. [QUOTE=CapsAdmin;25636197]Yeah I don't like typing ~= either. It's probably only like that for us Scandinavians though. We have to double press a button near enter, then it makes the symbol twice like so ~~ and then we need to remove one and then we can make =[/QUOTE] For us West Europeans and Americans probably, it's Shift+(Key above tab) and it only creates one.
A quick google says it's linux shell scripting. I didn't know that but I've seen the weird syntax a few times before from somewhere.
[QUOTE=CapsAdmin;25636250]A quick google says it's linux shell scripting. I didn't know that but I've seen the weird syntax a few times before from somewhere.[/QUOTE] [url=http://en.wikipedia.org/wiki/ALGOL_68]Algol 68[/url] seems to use if-fi, do-od, case-esac at least.
[QUOTE=CapsAdmin;25635123]What are the design flaws?[/QUOTE] DISCLAIMER: Im not a fan of javascript in any way. [url]http://www.google.com/search?q=javascript+bad+parts[/url] Only a function creates a new scope, leads to ugly shit like: [code] (function(){ alert("Lua is superior."); })() [/code] If you take a look at a javascript library, they are contained in one such block, if not i dunno wtf you found. Instead of local they use var, which is a confusing way to define that the variable is local to this scope, and they are only local to nearest function. The language is overall inconsistent. It was rushed. But the language is stuck with all the flaws it had 1995, all that can be done is add more bloat on top of it. Javascript feels like someone just mixed a couple of languages and came up with some random shit that made the features list of Netscape longer. (This is probaly how it happened) IMHO Lua is superior in every fucking way it could be. Anyone suggesting this language for use outside of a browser world where it sadly belongs, should be ashamed. I can't stress enough how much shame i wanna pour on you. With a grain of salt i claim LuaJIT to be [url=http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=luajit&lang2=v8]faster[/url]. Nothing can explain the anger i experience when i touch javascript.
I didn't look at examples much but from what I saw it looked the same as Lua in a way. After reading a bad parts article and your post I wouldn't use it at all. I prefer Lua as a scripting language.
[QUOTE=grea$emonkey;25634665]...but I don't see why making a javascript interpreter would be impossible. It would probably be a pain to make it, and kind of pointless since Lua's syntax is so similar.[/QUOTE] Of course, it wouldn't be hard at all. Now creating JS <-> GMod bindings, on the other hand...
[QUOTE=CapsAdmin;25636197]Yeah I don't like typing ~= either. It's probably only like that for us Scandinavians though. We have to double press a button near enter, then it makes the symbol twice like so ~~ and then we need to remove one and then we can make =[/QUOTE] Actually you just have to press that button once. When you make = after it, it will turn into ~= automatically. Something I noticed a long time ago.
Sorry, you need to Log In to post a reply to this thread.