• Glua vs Lua
    11 replies, posted
I am asking for friend that dosent believe Glua is just lua with editions, and thinks you can do better performance and less bugs with vanilla lua and i am saying you cant do anything that game dosent support anyway, Glua supports functions and he insist it should be used as only lua with modding GMod and i am saying just use GLua for functions, its editted lua anyway also since both are scripting language speed still depends on intepreter so there wont be much difference Why refuse to use a variation of lua that supported by the game since it still lua? What do you think? Also i dont know much about Glua since i didnt developed addons for game but i do game development myself
It's a little hard to understand some of what you're asking, but to answer 2 of the questions I got out of this 1. Is GLua just Lua with editions Pretty much, GLua is just an edited version of LuaJIT to make some C operators work. All of the extra functions are either created in the default Lua files for the game, or are bound to C++ functions. I wouldn't say the extra functions would make it uniquely GLua considering that's done for practically every project that uses Lua. 2. You can get less bugs and better performance with vanilla Lua You can write bug free code easily, it just depends on how good you are at writing code. Lua isn't like C where bugs will pop up out of no where because you're referencing a null pointer somewhere deep in your code. On the performance side of things "GLua" is usually faster as it uses LuaJIT, of course if that's disabled then it'll run practically the same.
These are the only differences between Lua and GLua that I know of: [url]http://wiki.garrysmod.com/page/Specific_Operators[/url] The alternate operators don't make any difference, there synonymous with the original Lua operator. This cannot introduce new bugs. The only meaningful change is the addition of the 'continue' statement. This statement doesn't exist in pure Lua because it's difficult to define how it would work in some edge cases - most notable a 'do until' loop. I don't know how GLua handles these edge cases, and I simply avoid using this statement to keep my code 100% pure Lua. (I also use the Lua-style operators) If you don't use 'continue', GLua and Lua are completely functionally identical to the best of my knowledge.
[QUOTE=bigdogmat;51292138]It's a little hard to understand some of what you're asking, but to answer 2 of the questions I got out of this 1. Is GLua just Lua with editions Pretty much, GLua is just an edited version of LuaJIT to make some C operators work. All of the extra functions are either created in the default Lua files for the game, or are bound to C++ functions. I wouldn't say the extra functions would make it uniquely GLua considering that's done for practically every project that uses Lua. 2. You can get less bugs and better performance with vanilla Lua You can write bug free code easily, it just depends on how good you are at writing code. Lua isn't like C where bugs will pop up out of no where because you're referencing a null pointer somewhere deep in your code. On the performance side of things "GLua" is usually faster as it uses LuaJIT, of course if that's disabled then it'll run practically the same.[/QUOTE] thanks that was what i told to my friend and he said it is a different language, this was what i said and i was thinking it should be like that since i actually looked for it and it was just reaching for some functions it is still lua.
In addition to what's been mentioned table.insert returns the index the value was placed at and "DEFINE_BASECLASS" is literally replaced with "local BaseClass = baseclass.Get" (try print("DEFINE_BASECLASS") ) LuaJIT doesn't perform at its best when you call C functions bound with the classic C lua api. There's a feature called trace stitching in LuaJIT 2.1 which solves some of this but currently gmod is at 2.0.something. Some official responses on this: [url]http://www.freelists.org/post/luajit/When-to-turn-off-JIT,5[/url] [url]http://www.freelists.org/post/luajit/Bug-with-tableinsert,1[/url]
[QUOTE=CapsAdmin;51295448]"DEFINE_BASECLASS" is literally replaced with "local BaseClass = baseclass.Get" (try print("DEFINE_BASECLASS") )[/QUOTE] Yes, that's Garry's beautiful way of solving software architecture problems. Change the interpreter to literally regex find and replace code before it's run through the lexer. Seriously, that shit was designed to do that.
[QUOTE=FPtje;51295803]Yes, that's Garry's beautiful way of solving software architecture problems. Change the interpreter to literally regex find and replace code before it's run through the lexer. Seriously, that shit was designed to do that.[/QUOTE] To be honest, I never quite understood what baseclass was even for. It's just confusing. There CAN BE proper inheritance in Lua using the __index metafunction (by simply setting it to the base class table), and there can be other tricks to make the base's elements visible even when they were overridden by the derived class. What the fuck is that local variable for? Sorry for going off-topic, though it doesn't matter since OP was already answered.
[QUOTE=NeatNit;51295845]To be honest, I never quite understood what baseclass was even for. It's just confusing. There CAN BE proper inheritance in Lua using the __index metafunction (by simply setting it to the base class table), and there can be other tricks to make the base's elements visible even when they were overridden by the derived class. What the fuck is that local variable for? Sorry for going off-topic, though it doesn't matter since OP was already answered.[/QUOTE] Bullshit like this is needed if you want to properly call methods of a base class from inherited class. Metatable __index shit will fuck up if your inheritance chain goes deeper than two classes. I had to solve this same problem too recently but I managed to do so without using Garry's bull.
[QUOTE=mijyuoon;51295942]Metatable __index shit will fuck up if your inheritance chain goes deeper than two classes.[/QUOTE] [lua]local tab_a = {a = "AAA"} local tab_b = {b = "BBB"} local tab_c = {c = "CCC"} local tab_d = {d = "DDD"} setmetatable(tab_d, {__index = tab_c}) setmetatable(tab_c, {__index = tab_b}) setmetatable(tab_b, {__index = tab_a}) print("tab_a", tab_a.a, tab_a.b, tab_a.c, tab_a.d) print("tab_b", tab_b.a, tab_b.b, tab_b.c, tab_b.d) print("tab_c", tab_c.a, tab_c.b, tab_c.c, tab_c.d) print("tab_d", tab_d.a, tab_d.b, tab_d.c, tab_d.d)[/lua] [url]https://www.lua.org/cgi-bin/demo[/url] output: tab_a AAA nil nil nil tab_b AAA BBB nil nil tab_c AAA BBB CCC nil tab_d AAA BBB CCC DDD [editline]2nd November 2016[/editline] Even works with the more common method of making __index a member of the table and using itself as a metatable: [lua]local tab_a = {a = "AAA"} local tab_b = {b = "BBB"} local tab_c = {c = "CCC"} local tab_d = {d = "DDD"} tab_a.__index = tab_a tab_b.__index = tab_b tab_c.__index = tab_c tab_d.__index = tab_d -- unused setmetatable(tab_d, tab_c) setmetatable(tab_c, tab_b) setmetatable(tab_b, tab_a) print("tab_a", tab_a.a, tab_a.b, tab_a.c, tab_a.d) print("tab_b", tab_b.a, tab_b.b, tab_b.c, tab_b.d) print("tab_c", tab_c.a, tab_c.b, tab_c.c, tab_c.d) print("tab_d", tab_d.a, tab_d.b, tab_d.c, tab_d.d)[/lua] Same output.
Metatables WILL fuck up when you need to do something like this (pseudocode): [code] class A def m() print("A::m") end end class B extends A def m() self.BaseClass.m() print("B::m") end end class C extends B def m() self.BaseClass.m() print("C::m") end end obj = new C() obj.m() [/code] The problem is that self.BaseClass in B::m() will still refer to B because self is an instance of C, so the self.BaseClass.m() call in B::m() will call B::m() instead of A::m() and it'll just die.
[QUOTE=mijyuoon;51296508]:snip:[/QUOTE] Oh, I see what you mean. That's a good point, I wonder how people have solved it in the past. I'm on a long bus ride so if I can't find a solution I'll give it a whirl. Thanks for the challenge :D
[QUOTE=NeatNit;51296637]Oh, I see what you mean. That's a good point, I wonder how people have solved it in the past. I'm on a long bus ride so if I can't find a solution I'll give it a whirl. Thanks for the challenge :D[/QUOTE] I solved it by adding base class metatable reference to child class metatable and calling base class methods through metatable itself, not through self. I have something like this in a .lua file for my custom UI system: [code] local UI = {} UI.UIName = "SomeUIObject" UI.UIBase = "BaseClassName" function UI:Method() UI.UIBaseClass.Method(self) -- do other shit end return UI [/code] Then after this file is executed, table gets registered in my UI system and .UIBaseClass field gets populated. It's kinda crap but it works.
Sorry, you need to Log In to post a reply to this thread.