Hey, this is really interesting.. K-Meleon's macro language is a bit limited (albeit quite enough for most common tasks), and I've heard that Lua is very powerful.
Thank you for testing and comments.
This plugin has worked well with mine.
I know K-Meleon's macro language is superior (simple, small, efficient, effective, and more). But it is weak on modularity. Understanding and managing a large macros.cfg is hard for me. I think that to reuse macros or to update customized macros.cfg is troublesome.
I aimed to offer the choices and to have discussion on macro language.
OK, I changed my mind. The Groups macro is not a good example at all. It's too complicated, made worse by my less-than-one-week-old experience with Lua .
I've uploaded a simple "search" macro which is a much better starting point. The sample "proxy" macro (in proxy.lua and a bit of macros.lua) is also good for starters; it's very well written.
Suggestion: use an editor which can do syntax highlighting for Lua. Don't use Notepad!
@rmn,
Thank you very much for your lua macros. It's a good starting point to learn those things from scratch. I'm trying to figure out more things lua could do in K-Meleon. Thanks again.
If you are looking for a Lua capable editor, try http://www.scintilla.org/SciTE.html. SciTE supports syntax-highlighting for Lua and can even use Lua internally.
> @rmn
That's great. I see you are more skilled in Lua than me. I'll study Lua with your scripts. Thank you.
Uh, no way, I didn't know any Lua before last week... your scripts are better written; and thanks a lot for the plugin! (And I'm pretty sure there are a few bugs in that groups script because I didn't know that the scripts only receive hwnd + 1 string param from K-Meleon. :-)
> @All
Do you have complaints about this plugin?
I feel that Lua scripts tends to be verbosity. And hwnd is ugly.
I can't think of any complaints right now, but I'm really curious about how it preforms in a slow machine. I'm just thinking, if this plugin is fast enough, it can replace macros.dll.... And the fact that we can add/remove scripts anytime means we don't have to load the ones that we don't need.
I think the verbosity isn't that bad (also, I don't really mind that hwnd thingy), and it's a very nice scripting language. By the way, does this mean we can manipulate other windows using their window handles?
Only just started reading this thread. The above got my attention and would be great. Of course we still run into the copy & pasting annoyance for the menu & accelerator files. It would be great if a user could just drop a file into his/her profile, restart and tada!...there it is revving to go :-)
The Groups macro is not a good example at all. It's too complicated
Wait 'til you see the convoluted mess of the Switch Proxy macro script I'm almost finished with :-). It'll make the Groups macro script look nice & clean....lol. As far as the lua group script's compatibilty with the direct macros group script, some adjustments would have to be made besides the pref changes. I sampled yours and I believe your groups are saved to prefs with an underscore preceding the name IINM? Little things like that would have to be changed. But there really is no reason for them to be compatible yet until we decided that lua scripts should replace direct macro scripts and therefore users' migrating to lua files wouldn't have to adjust their prefs.
I've just realised that it isn't really plug-and-play, because we still need to add 'require "scriptfile"' to macros.lua, but at least that's only one line, and doesn't make your macros.cfg grow uncontrollably .
> your groups are saved to prefs with an underscore preceding the name IINM?
Yep, and that's what the groups.pref.GROUPS variable does (it's the prefix for the group prefs; should've named it "prefix" or something). Anyway, it wasn't my intention to create a usable script; I did it just as an exercise.
It may be just a step more user-friendly than the current macros plugin, but i think the main advantage of this is that it's easier to manage (more organized because different macros each have their own file) and more powerful, but mostly that it's more powerful.
Add: OnQuit
Add: Plugin command 'Eval'
Add: Popup menu and select dialog.
Add: New samples. search, viewlinks.
Add: Include pre-compiled standalone interpreter and byte compiler.
They don't link K-Meleon API, ant yet the compiler can compile
scripts. Then the interpreter is maybe useful to study Lua.
Fix: Instructions
Plan: Add anoother path to 'LUA_PATH'.
Plan: Agreements with naming and structure.
If you have idea, please tell me.
Thanks for reading. Have a nice weekend.
I don't know how the lua plugin calls functions, but if it calls them the way I think it does (ex: "lua(TogglePref)"), then do you think that it'd be better to find a way to specify the filename of the script, then colon, then the lua macro... something like:
lua(FILENAME:TogglePref)
Of course, you wouldn't need to include the .lua extension... just the filename.
Can this even be done? Is it necessary to prevent macros with the same name from different scripts from clashing?
In the fact, I didn't know it. I thought we need to classify public or private functions by name. But I get it is needless. Thank you for your question. However I think that we must have a consensus about a foundation structure such as hook mechanism or filesystem structure.
If you mean the former, I will think to do. But it is probably difficult, because to do needs to solve dependency of modules.
The limitation of filename extension comes from require Lua function, and it can omit by changing LUA_PATH gloval variable. But if this plugin can load all files, this would load non-lua files.
Oh, I mistake. orz
We don't need a consensus about LUA_PATH. If you want to put Lua scripts (except macros.lua) into other folder, you may modify LUA_PATH before calling "require" such below:
(typically it's on head of "macros.lua"). It means you put Lua scripts into "lua" subfolder in your profile folder. Filename extension have to be specified yet. But I think good that Lua scripts are named with ".lua" extention.
Thanks.
Hey, that select() function is quite handy. I've updated my Groups script to use it.
I've also been playing around with the naming to see how I can separate KM-callable functions from the 'private' functions. Now I put them in different tables and make one of them local. That seems to make the code look nicer.
Change: Lua 5.1 beta
Change: "select" function is renamed to "choose", because Lua 5.1 has "select" function.
Fix: Memory leak on EncodeUTF8 and DecodeUTF8 function.
Fix: "id" function couldn't handle number ID correctly.
Improve: More detailed error message.
Improve: "SetCheck" function can handle string ID.
Remove: Pre compiled Lua binaries.