lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> 2008/6/23 Asko Kauppi wrote
>> For a ported serial module, see:
>> http://lua-users.org/lists/lua-l/2007-09/msg00465.html
>> Stefan's link seems to be down, has anyone have a more recent URL?

Here's some code I once used for controlling Win32 serial
communications ports from Lua using Alien:

  http://lua-users.org/wiki/SerialCommunication

Still, I agree it may be useful if someone posted a plain C binding
too and built a rock, as RS-232 control is a fairly basic need.


Incidentally, in regards to a recent discussion, this was another
example where bit manipulation operations were needed in Lua.  For
that I just used Rici's functions, which are only five lines:

-- bitwise operators
-- based on http://ricilake.blogspot.com/2007/10/iterating-bits-in-lua.html
-- 1-based indexing
local function bit(p) return 2 ^ (p - 1) end
local function hasbit(x, p) return x % (p + p) >= p end
local function setbit(x, p) return hasbit(x, p) and x or x + p end
local function clearbit(x, p) return hasbit(x, p) and x - p or x end
local function changebit(x, p, b) return b and setbit(x,p) or clearbit(x,p) end