• 0

    posted a message on Code Review. OrChoose, RelationalChoose
    Very Every Well Wheel:

    I have finished my readings about Lua Metatables, "OO" and Weak tables; my conclusion:
    Implementation of Metatables seams the best option this language can offer me, as the manual says (more or less) "the way metatables work is hard coded in lua" I just hope so.

    In many cases the use of OrC can be replaced with the __index metamethod, and even in some cases the "or" assignation seams to work (still testing).

    Thanks a lot to everyone.
    FF.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code Review. OrChoose, RelationalChoose
    Thanks a lot.
    I will try to read all about metatables tomorrow; in the while (I know this has the waste table but is quite simple (I will clean it after)):

    instead of defining OrC with the if, what about this:

    function FreeFog.Q.Function.Values.OrChoose (v1,v2,v3)
    	local t = {};
    	t[v2 == v3] = v2;
    	t[v1 == v3] = v1;
    	return t[false]
    end



    Q4: This has 2 comparisons but there is no way this can beat the single if with an else right?. (Again tomorrow I will read all about meta tables and lua objects).

    Almost forgot in the Old OrC I put the ~= since v1 is intended to be the "value with privileges" so I tried to skip the else and reflect that by putting the condition that will out put v1 first;
    Q5: Does that really saves any resource or the else is some how "taken into account" even if not needed.

    FF.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code Review. OrChoose, RelationalChoose
    Example:

    I have a group A, G_A with it's general properties and group G_A individuals G_A_I with it's personal properties; whenever I define property P I give individuals properties overwrite privileges over group properties, to choose I use OrC:

    Other_Group_Individual.property_name = OrC(G_A_I.property_name, G_A.property_name);


    If G_A_I.property_name exists then it will be the new property value else it will assing the group general property or if none exists nil.

    Other ex (this one not tested):
    local bType = OrC(buttonData.Property.Frame_Type, buttonsGroup.Property.Frame_Type);
    local bName = OrC(buttonData.Property.Name, name .. "_Button_" .. buttonIndex);
    local bParent = OrC(buttonData.Property.Parent, buttonsGroup.Property.Parent);
    local bTemplate = Orc(buttonData.Property.Template, buttonsGroup.Property.Template);
    		
    local button = CreateFrame(bType, bName, bParent, bTemplate);



    More or less is the same for LoC, is to work with vars assignments.

    Plz If I am still not writing clear let me know Or even more dangerous to my, If any normal practice solves this let me know.
    FF.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code Review. OrChoose, RelationalChoose
    In function FreeFog.Q.Function.Values.RelationalChoose;
    Q3: Putting an if clause like this can improve something?:

    if (o == ">") then
    	t[">"] = (v1 > v2);
    end
    if (o == "==") then
    	t["=="] = (v1 == v2);
    end
    if (o == ">=") then
    	t[">="] = (v1 >= v2);
    end
    Posted in: Lua Code Discussion
  • 0

    posted a message on Code Review. OrChoose, RelationalChoose
    Hello there:
    (again I apologize for what I did yesterday)

    Suppose:
    ----------------------------------------------------------------------------------------------------
    local function print (s)
    ----------------------------------------------------------------------------------------------------
    	DEFAULT_CHAT_FRAME:AddMessage(tostring(s));
    end
    ----------------------------------------------------------------------------------------------------
    ----------------------------------------------------------------------------------------------------
    FreeFog = {};
    FreeFog.Q = {};
    FreeFog.Q.AddOn = {};
    
    FreeFog.Q.Function = {};
    FreeFog.Q.Function.Values = {};
    ----------------------------------------------------------------------------------------------------
    --Polish 3 Move to library
    function FreeFog.Q.Function.Values.OrChoose (v1,v2,v3)
    ----------------------------------------------------------------------------------------------------
    	if (v1 ~= v3) then
    		return v1;
    	else
    		return v2;
    	end
    end
    ----------------------------------------------------------------------------------------------------
    function FreeFog.Q.Function.Values.RelationalChoose (v1,v2,o)
    ----------------------------------------------------------------------------------------------------
    	local t = {};
    
    	t[">"] = (v1 > v2);
    
    	t["=="] = (v1 == v2);
    
    	t[">="] = (v1 >= v2);
    
    	if t[o] then
    		return v1
    	else
    		return v2
    	end
    end
    --Polish 3
    ----------------------------------------------------------------------------------------------------
    
    ----------------------------------------------------------------------------------------------------
    local OrC = FreeFog.Q.Function.Values.OrChoose;
    local RoC = FreeFog.Q.Function.Values.RelationalChoose;
    
    local var_1 = 1;
    local var_2 = 2;
    
    local OrC_Example_If_AnyExist_Assing = OrC(var_nil, var_1);
    print (OrC_Example_If_AnyExist_Assing);
    
    local RoC_Example_Assing_What_Makes_Condition_To_Be_True = RoC(var_1, var_2, ">");
    
    print(RoC_Example_Assing_What_Makes_Condition_To_Be_True);
    ----------------------------------------------------------------------------------------------------
    
    At lest in my test it printed:
    1
    2


    1 was assigned to OrC_Example_If_AnyExist_Assing since the only argument parsed that existed was var_1.

    2 was assigned to RoC_Example_Assing_What_Makes_Condition_To_Be_True since the greater value (">") among var_1 and var_2 is var_2.

    I see many uses for this functions but:

    Q1a: I know there are some lua equivalents to do part of the job, like math.max to replace >, but how can I implement them?. Q1b: If it is positive to implement them witch are the equivalents?.

    Q2: If the above was good how can it become better?.

    Thanks in Advance.
    FF.

    Posted in: Lua Code Discussion
  • 0

    posted a message on Doubts With Vararg
    /e FreeFog puts his head down

    I have to apologize tested again and worked.

    About select('#',...), I mean before in fact select(number,...) and returned me just one string word, I don't know what I did wrong before.

    Sorry.
    FF.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Doubts With Vararg
    You are all a bunch of LOLs XD.

    Plz don't post with out thinking and thanks for all that don't post compulsively and have tested in the past what they teach today.

    Else I tested print( select('#',...) ) and only returns "Line1".

    Thanks for OrionShock for concise working post. All the rest don't work.

    If I put that the out put was a table that means that the print function was defined, but as I didn't tell what was the error I can't say a word.

    Still.

    I'm quite dissatisfied one of the biggest advantages of vararg was that you saved a microscopic effort to the system coz it reused a table. If any one has a trick or the best way to use vararg I'm all eyes to new ideas.

    Thanks to everybody.
    FF.
    Posted in: Lua Code Discussion
  • 0

    posted a message on Doubts With Vararg
    (Edited)
    OutPut:

    Nice short answer:
    http://forums.worldofwarcraft.com/thread.html?topicId=3547589579&postId=35472316107&sid=1#1

    Complete threat and discussion below:
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



    Tried Tried and Tried and I keep missing:


    Suppose:
    function pipo (...)
    print(arg);
    local a,b,c,d = unpack(arg);
    print(a,b,c,d);
    end
    pipo("Line1","Line2","Line3","Line4");


    Based on lua.org doc and my interpretation that should out put:
    table: <tablename>
    
    Line1,Line2,Line3,Line4

    But the only I get are errors.

    Note:
    If I replace:
    local a,b,c,d = unpack(arg);

    for:
    local a,b,c,d = ...;

    I get that ... is a string with the value Line1.


    Q1: How should I use the vararg expression?.


    Any help really appreciated and sorry for your time.

    FF.
    Posted in: Lua Code Discussion
  • To post a comment, please or register a new account.