Variable assignment syntax

Section for all discussions related to development using Indicore API/SDK.

Moderator: admin

Variable assignment syntax

Postby sllouw » Sat Mar 26, 2016 8:57 am

In respect of the TRADESESSIONS.lua indicator there is a certain function which has a local variable named session.
This indicator is described in this post:
http://fxcodebase.com/code/viewtopic.php?f=17&t=1974
The code is sourced at this earlier post here
http://74.52.98.35/code/viewtopic.php?f=17&t=940&sid=a4b312dd44113f005a0785088088828f

Q1 The variable session is declared as shown below. What do the curly brackets {} mean?
Code: Select all
    local session = {};

Q2 There follow various references to what are apparently properties of the variable.
for example session.id, session.labels, session.name, session.from etc and others. What data structure is this from? The first 10 lines of code show these assignments below:
Code: Select all
function CreateSession(from, len, color, name, iname, labels)
    local session = {};
    local n;
    session.id = gId;
    gId = gId + 10;
    session.labels = labels;
    session.name = name;
    session.from = from;
    session.color = color;
    session.len = len;



The full code for the function in question is below:
Code: Select all
function CreateSession(from, len, color, name, iname, labels)
    local session = {};
    local n;
    session.id = gId;
    gId = gId + 10;
    session.labels = labels;
    session.name = name;
    session.from = from;
    session.color = color;
    session.len = len;
    n = name .. "_H";
    session.high = instance:addStream(n, core.Line, iname .. "." .. n, name .. "H", color, local_first);
    session.high:setStyle(instance.parameters.STYLE);
    n = name .. "_L";
    session.low = instance:addStream(n, core.Line, iname .. "." .. n, name .. "L", color, local_first);
    session.low:setStyle(instance.parameters.STYLE);
    session.highband = instance:addInternalStream(local_first, 0);
    session.lowband = instance:addInternalStream(local_first, 0);
    session.begin = instance:addInternalStream(0, 0);
    instance:createChannelGroup(name, name, session.highband, session.lowband, color, 100 - instance.parameters.HL);
    if labels and (S_H or S_OH or S_OD) and not(S_TT) then
        session.LH = instance:createTextOutput("", name .. "_HL", "Arial", instance.parameters.FS, core.H_Right, core.V_Top, color, 0);
    end

    if labels and (S_L or S_OD) and not(S_TT) then
        session.LL = instance:createTextOutput("", name .. "_LL", "Arial", instance.parameters.FS, core.H_Right, core.V_Bottom, color, 0);
    end

    if labels and S_N then
        session.LN = instance:createTextOutput("", name .. "_LN", "Arial", instance.parameters.FS, core.H_Right, core.V_Top, color, 0);
    end
    return session;
end
sllouw
 
Posts: 23
Joined: Tue Mar 08, 2016 8:28 am
Location: Queensland Australia

Re: Variable assignment syntax

Postby Julia CJ » Mon Mar 28, 2016 7:51 am

Hello Sllouw,
What do the curly brackets {} mean?


This is the designation of the table, i.e empty table. More information about the table as an object in Lua language you can read here:

http://www.lua.org/pil/2.5.html

What data structure is this from?


There is no the specific structure of line location. In the code you write the lines are at your discretion, i.e you define the sorting order yourself.
Julia CJ
 

Re: Variable assignment syntax

Postby sllouw » Sat Apr 02, 2016 1:21 am

Thank you Julia
I have a feeling I will be saying this often :) :oops:
sllouw
 
Posts: 23
Joined: Tue Mar 08, 2016 8:28 am
Location: Queensland Australia


Return to Discussions

Who is online

Users browsing this forum: No registered users and 2 guests