Re: Single instance module and multithreading

From: mitchell <mforal.n....at.gmail.com>
Date: Sun, 22 Feb 2009 18:15:36 -0800 (PST)

Hi,

> You are correct. I guess I am still unsure as to how exactly Lanes
> functions. I am thinking passing by reference, not by value. It
> appears Linda and executing commands on 'view_switch' is the way to
> go.

This version has been tested and works. I placed it inside the 'if not
RESETTING' conditional inside init.lua.
Right now it closes the server after receiving a single connection.
This will need to be fixed of course, but I don't know how to accept
clients in a while loop while still closing the server on exit.

  require 'socket'
  require 'lanes'
  local linda = lanes.linda()
  local port = 3000
  function lane()
    local socket = require 'socket'
    local server = socket.bind('localhost', port)
    local client = server:accept()
    linda:send('command', client:receive())
    server:close()
  end
  local l = lanes.gen("*", lane)()
  textadept.events.add_handler('view_switch',
    function()
      cmd = linda:receive(0, 'command')
      while cmd do
        pcall(loadstring(cmd))
        cmd = linda:receive(0, 'command')
      end
    end)
Received on Sun 22 Feb 2009 - 21:15:36 EST

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:37:32 EST