mikshaw
Group: Members
Posts: 4856
Joined: July 2004 |
|
Posted: Feb. 09 2007,04:29 |
|
Here's a nice collection of Lua code snippets and functions: http://lua-users.org/wiki/SampleCode
Some work as-is in murgaLua, and some need a little modification. For example, the length_of_file function on the "File Input Output" page uses assert, which crashes murgaLua if the file doesn't exist instead of just giving an error message. I used "if" instead to check if io.open worked:
Code Sample | function length_of_file(filename) local fh = io.open(filename, "rb") if fh then local len = fh:seek("end") fh:close() return len end end |
The original function was written by Jay Carlson, the creator of Lua-FLTK
If anyone else knows of a good resource for Lua samples, please paste a link here. thanks. -----------------------------
Here are a couple I did yesterday while working on another project (murgaLua only):
-- Returns a hex value from the given widget's color. -- In the case of redthing:color(fltk.FL_RED) -- hexcolor(redthing) returns #FF0000
Code Sample | function hexcolor(widget) local r,g,b=Fl:get_color(widget:color(),r,g,b); local hex=string.format("#%.2X%.2X%.2X",r,g,b); return hex end |
-- An alternative to the above, which uses a color index (0-255) as -- an argument. You can plug in any FLTK color rather than rely on -- a specific widget's base color. Numbers above 255 will work, but -- I couldn't tell you what rgb values they represent =o)
Code Sample | function hexcolor2(num) local r,g,b=Fl:get_color(num,r,g,b); local hex=string.format("#%.2X%.2X%.2X",r,g,b); return hex end |
-------------- http://www.tldp.org/LDP/intro-linux/html/index.html
|