Results 1 to 4 of 4

Thread: Reference Lua Variable from within Object Super Subclass

  1. #1
    Join Date
    Sep 2008
    Posts
    150

    Default Reference Lua Variable from within Object Super Subclass

    I'm using the 'standard' transport lua code for some coms links, one of which I want to analyse the received data, and depending on what is contained in the received string to set a variable to a status.
    I am using a CM11 X10 transceiver to control my lights and I would like this connected via a TCPIP -RS232 link, but the CM11 plugin can only reference a com port, not a IP address and the virtual com port software I've tried is not that robust.
    Plus as the protocol does not seem too onerous, I thought I would have a stab at coding it myself as a transport.

    So as an extract (I've missed the middle bit out as it is standard)

    Code:
    local Object = Super:Subclass ( {
    
        Name = 'X10CM11Link',
        Description = 'X10 CM11 Link',
        GUIDefaults = {
            allowedtransports = {
                [constants.transport.GIP] = true,
                [constants.transport.SERIAL] = true,
            },
            defaulttransport = constants.transport.SERIAL,
            baud = 4800,
            port = 7,
        },
        
        	local c = ComponentManager:GetComponentUsingName("Transport Manager")
    	local tx = c:GetTransportUsingName("My X10CM11Link")
    	self.MacroCodeSent = false
    	self.SetupCodeSent = false
        
        OnReceiveData = function(self, Event)
            print(self.Name .. " Received: ")
    	local s = math.bytetohex(Event:GetData())
    	print(math.formatbytes(s))
    	
    	if s == "55" then
    		HOUSE.X10.CM11Ready = true
    	end
    	
    	if s == "5A" then
    		tx:Send (math.hextobyte("C3"))
    	end
    So when I receive "55", I want to set the variable:
    Code:
    HOUSE.X10.CM11Ready = true
    But this sets:
    Code:
    Transport.X10CM11Link.HOUSE.X10.CM11Ready = true
    I believe that I understand that being an object, everything is referenced to that object name, but how do I break that reference and force a reference from the beginning of the Girder variable name space?
    I've tried random things like \G and girder. etc. But none seem to work.

    With thanks
    Jon
    Last edited by jon1977; December 6th, 2013 at 06:43 AM.

  2. #2
    Join Date
    Sep 2008
    Posts
    150

    Default

    Bump.
    Any advice with this?
    With thanks.
    Jon.

  3. #3
    Join Date
    Sep 2008
    Posts
    150

    Default

    Bump.
    I have a new programming issue where I want to do exactly the same thing as above!
    Any advice?
    With thanks
    Jon

  4. #4
    Join Date
    Jan 1998
    Location
    Jupiter, FL
    Posts
    13,553

    Default

    I believe _G ( underscore G ) gives you access to the global state.
    Ron
    No support through PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •