Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 01, 2015, 09:14:34 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: FLua: FARR Plugins Using Lua  (Read 5380 times)

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • gravatar avatar
  • Posts: 2,702
    • View Profile
    • Donate to Member
FLua: FARR Plugins Using Lua
« on: July 02, 2010, 09:38:25 AM »
I've been working on trying to make it possible to write plugins for FARR in Lua and there is now something that seems to work somewhat so...

The design is almost completely based on ecaradec's FScript (many thanks to him for releasing the source to that).  I haven't implemented timers yet, but other things are somewhat in-place.  If you've used FScript before, the interface should feel very familiar. 

Had some luck with following:

  • on_init
  • on_set_str_val
  • on_search_begins
  • on_regex_search_match
  • on_process_trigger
  • farr_set_str_value
  • farr_get_str_value
  • farr_emit_result
  • farr_set_state
  • farr_emit_results (this may be more convenient than using the last two)

Implemented but didn't really test:

  • on_receive_key
  • on_idle_time

Below is a link to a sample Lua plugin.  It is supposed to be similar to vitalyb's FARREnvironmentVariables plugin.

It's got some issues (e.g. DOS window showing up momentarily), but anyway:

  http://ewemoa.dcmemb...p/LuaPathEnvVars.zip

SHA-1: 50f501d3d6e85b7ea3052e76b13ecda58ca8be72

The contained files and folders are:

  • FLua.dll
  • flua.lua
  • LICENSES\
  • LuaPathEnvVars.ico
  • plugin.lua
  • README.txt <- pretty much useless at this point

The main file to tinker with at this point is plugin.lua.

Any comments welcome :)

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 34,968
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #1 on: July 02, 2010, 03:39:36 PM »
amazing  :-* :-* :-*

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,218
    • View Profile
    • Coding Snacks by Lanux128
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #2 on: July 03, 2010, 12:37:31 AM »
nice.. :up: btw, i'm not well-versed with Lua, is it easy to pick up?

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • gravatar avatar
  • Posts: 2,702
    • View Profile
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #3 on: July 03, 2010, 01:23:11 AM »
From what I understand, there was (and may be still is?) quite a bit of effort on the parts of the creators/maintainers (3 people as I understand it) to keep the language simple -- internally and externally.

Conceptually it reminds me a lot of Lisp/Scheme but with a syntax that feels more mainstream (though not really C-like).

To give you a taste, here's a snippet from plugin.lua (from the sample plugin):

Code: Text
  1. function on_init(
  2.   directory
  3. )
  4.   odprintf("    current working directory is: " .. lfs.currentdir())
  5.   plugin_dir = directory
  6.   odprintf("    plugin_dir set to: " .. directory)
  7.   determine_envvars()
  8.   return true
  9. end
  10.  

Below is an attempt at explaining the content (if there are other Lua folks around and see errors please speak up :) ).

This is a function definition.

Lines 1-3 are the portions that indicate a name for the function and a parameter names (the parameter being on separate lines is just a style I am experimenting with -- haven't seen any one else do this in Lua).  The name of the function is 'on_init' and it has one parameter named 'directory'.

Line 4 is a function call.  The argument is the result of concatenating (via ..) two things, a string and the result of another function call (the function currentdir in the module lfs)).

Line 5 is an assignment of the passed in value of 'directory' to the 'plugin_dir' variable (which currently is global).

Line 6 is another function call, similar to line 4.

Line 7 is a call to another function defined elsewhere in plugin.lua.

Line 8 is a return statement.  It returns a boolean true value.

Line 9 delimits the end of the function statement.

For reference, some potentially handy Lua resources:

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

  Programing in Lua (1st edition, covers a slightly older Lua, but still quite useful)
    http://www.lua.org/pil/

  The Programming Language Lua
    http://www.lua.org/

ecaradec

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 409
    • View Profile
    • Blog & Projects
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #4 on: July 04, 2010, 05:21:01 AM »
This rocks ! I didn't know any lua, but I heard it's a great language and FLua is a native port (not activescripting ). People won't probably notice, but this will certainly prove much more flexible. Now I have a very good reason to learn Lua.

Do you know if FLua can use external libraries from lua ? That was lacking with FScript.

It certainly was a lot of work, even starting from FScript code... Thank you so much !
Blog & Projects : Blog | Qatapult | SwiffOut | FScript

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • gravatar avatar
  • Posts: 2,702
    • View Profile
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #5 on: July 04, 2010, 07:12:35 AM »
Do you know if FLua can use external libraries from lua ?
Depending on what you mean, I think it may be doable (perhaps in more than one way).

See:

  http://lua-users.org...iki/BindingCodeToLua

Specifically, some bits I'm thinking of trying include:

  http://alien.luaforge.net/
  http://www.nongnu.org/cinvoke/lua.html

Quote
Thank you so much !
Thank you for FScript and its source :)

BTW, the DLL is built using Code::Blocks and MinGW.  I'm hoping to clean up the source and make it generally available before too long.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • gravatar avatar
  • Posts: 2,702
    • View Profile
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #6 on: July 09, 2010, 12:42:40 AM »
Specifically, some bits I'm thinking of trying include:
  http://alien.luaforge.net/
I've been trying to get alien to work with FLua but haven't had much luck so far.  Actually, it looks more like some kind of problem building alien (or libffi which alien uses) using Code::Blocks / MinGW.  Compilation is successful but when trying to do something as simple as:

Code: Text
  1. require('alien')
  2. mb = alien.User32.MessageBoxA
  3. mb:types({ret = "long", abi = "stdcall", "long", "string", "string", "long"})
  4. mb(0, "Hey!", "From Lua", 0)
  5.  

The host application (whether it's FARR of lua.exe) crashes at line 4 :(

ecaradec

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 409
    • View Profile
    • Blog & Projects
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #7 on: July 09, 2010, 06:29:02 AM »
Actually I was talking about lua libraries which I saw you can use in sources. Calling DLL would be neat too, but lua libraries open a lot of doors already.
Blog & Projects : Blog | Qatapult | SwiffOut | FScript

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • gravatar avatar
  • Posts: 2,702
    • View Profile
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #8 on: July 09, 2010, 09:01:47 AM »
Thanks for the follow-up comment.

I intend to continue looking into getting Alien to work, but in the mean time, here is a rearranged Flua:

  http://ewemoa.dcmembers.com/tmp/FLua-2010-07-09.zip

SHA-1: fd0c178adf51726d529c2e4edc5cd9c753b81add

The main difference in this version is that the core lua portion lives in its own dll (luadll.dll) and that FLua.dll and lfs.dll both link to luadll.dll.

Also included are rex_pcre.dll (also linked to luadll.dll) with pcre.dll and a minor amount of related test code in plugin.lua.
« Last Edit: July 09, 2010, 08:22:48 PM by ewemoa »

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • gravatar avatar
  • Posts: 2,702
    • View Profile
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #9 on: July 09, 2010, 05:31:00 PM »
Here's something preliminary for sqlite 3 access:

  http://ewemoa.dcmemb...com/tmp/lsqlite3.zip

SHA-1: 9de918c90409e4c9cfa879decf5c1d91af07868b

Some brief docs are included for lsqlite3 usage, but the original distribution has more detail. 

To install for use with FLua, I think all that is necessary is to place lsqlite3.dll and sqlite3.dll in the FLua plugins folder.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • gravatar avatar
  • Posts: 2,702
    • View Profile
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #10 on: July 09, 2010, 08:39:15 PM »
FLua-2010-07-09.zip contained a lua.exe (for interactive fun and testing) which might lead to problems.

The following has a (hopefully) fixed lua.exe along with a lightly-tested LuaSocket:

  http://ewemoa.dcmemb.../FLua-2010-07-10.zip

SHA-1: 2dd74629b0f8487444214dfdac1ae548880dff98

Short sample of LuaSocket use:

Code: Text
  1. http = require("socket.http")
  2. print(http.request("http://donationcoder.com"))
  3.  

For more details, please see the reference.

phitsc

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 1,104
    • View Profile
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #11 on: July 22, 2010, 02:57:01 PM »
I agree with ecaradec. It's really cool that you have done this ewemoa!  :Thmbsup:

I've wanted to look into lua for a long time, have several times considered using it for work even, and have read quite a bit about it too (I confess: I'm a big fan of the Game Programming Gems series :)).

I promise I'll check this stuff out as soon as I manage to come loose from Red Dead Redemption ;)

ecaradec

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 409
    • View Profile
    • Blog & Projects
    • Donate to Member
Re: FLua: FARR Plugins Using Lua
« Reply #12 on: August 14, 2010, 01:06:55 PM »
Just a word to tell that you can consider fscript under the lgpl, mit license or even the even the WTFPL as you like, in case I disappear somewhere.
Blog & Projects : Blog | Qatapult | SwiffOut | FScript