script plugin

Script Plugin (LUA) development forum
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: script plugin

Post by petah »

let me know if my explanation wasn't clear ("le quai des brumes" ;)) and I'll revise it.

The gist of my proposal is that the script hook UI actually be a "dumb"/passive/generic property table, and not specific to scripts, on entry it builds the UI by generating rows of widgets whose definition it receives from Lua, and on exit (modification) it sends updated values to Lua which handles the actual script hooking with the function from your API.

edit: I found a wx control that does +/- what I meant: http://docs.wxwidgets.org/trunk/overview_propgrid.html, though it may be a bit overkill. Also I think a better event model is for an edited control to only notify Lua there has been a change, then for Lua to retrieve the data, i.e. a "pull" model, not push, so repeated changes don't push stale data to Lua.

a+

-- p
main: Debian Jessie x64 + custom wxTrunk
jfouche
CodeLite Guru
Posts: 351
Joined: Mon Oct 20, 2008 7:26 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: script plugin

Post by jfouche »

Here is a first version of the plugin (based on git head). As I only have a Windows machine, I can only provide a Windows version of the plugin... sorry :?
Of course, feedback is welcome. Moreover, as it is, the current API is enough for my own needs. But I can add all bindings you need to extends the current API.

To install it, you must extract the 7z content to your plugins directory.

This plugin provides a toolbar with 2 buttons :
- Show scripts : shows / hide a miniframe which contains all "on demand" script. Double clicking on a script runs it.
- Scripts settings : it show a dialog that allow you to add / remove scripts (on demand script or hooks scripts).

All scripts embed a global "codelite" variable, you can use to interract with codelite.
Here is the API :

codelite
  • codelite.manager : gives you acces to the IManager
  • codelite.Trace(str) : add a trace in the trace tab
  • codelite:Bind(evendId, function) : This function is only usefull when creating a hook script. It binds the function to the current event. Currently, only the wxEVT_FILE_SAVED has been implemented.
IManager
  • manager:GetActiveEditor() : return the current editor or nil
  • manager:NewEditor() : Create a new editor, and returns it
  • manager:GetWorkspace() : return the workspace or nil
IEditor
  • editor:GetEditorText() : return the text of the editor
  • editor:SetEditorText(str) : set the content of the editor
  • editor:GetSelection() : return the current selection
  • editor:ReplaceSelection(str) : replace the current selection with the given string
  • editor:AppendText(str) : Append the given string at the end of the editor
  • editor:GetCurrentPosition() : return the position of the caret
  • editor:InsertText(int, str) : Insert text at the given position
Workspace
  • workspace:GetActiveProjectName() : return the name of the active project
  • workspace:GetProjectList() : return a table containing all project names
  • worspace:FindProjectByName(str) : return the project named with the given string, or nil
Project
  • project:GetName() : return the project name
  • project:GetFiles() : return a table containing all file paths
Event
  • event:GetString() : return the string, depending on the event context
Here is a "on demand" script which allow you to comment the current selection :

Code: Select all

editor = codelite.manager:GetActiveEditor()
if editor then
	sel = editor:GetSelection()
	if #sel > 0 then
		text = "/* " .. sel .. " */"
		editor:ReplaceSelection(text)
	end
end
And here a hook script which trace each saved files

Code: Select all

local f = function(event)
	codelite.Trace("FILE SAVED : " .. event:GetString())
end

codelite:Bind(wxEVT_FILE_SAVED, f)
You do not have the required permissions to view the files attached to this post.
Jérémie
jfouche
CodeLite Guru
Posts: 351
Joined: Mon Oct 20, 2008 7:26 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: script plugin

Post by jfouche »

Salut Pet'

Currently, I didn't ear you at all... but I'm not deaf ;)
You have lot's of idea, but my current idea is to provide a very simple plugin.
The step to implement what you want seems to be very complicated (at least for me, who learned Lua during this plugin development), and needs a huge API, not only based on codelite, but also on wxWidgets.

If you want to help me (and I hope you will), I think we should define a step by step roadmap.

See you
Jérémie
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: script plugin

Post by petah »

Slt Jem'

you're right - I iterate on ideas too fast (literally before finishing a sentence) and the end result seems pretty convoluted but it's just because there are more look-ups. I can't help trying to see the "big picture", which I think you'll get to eventually and it'll be easier to debug smaller evolutionary changes. I may be getting ahead of myself and missing better solutions you'll spot along the way.

I just finished my 3rd Lua debugger revision http://www.laufenberg.ch/ddt3/ but still need to integrate it into my customer's 3d engine so will be busy for a while still. Anyway the CL plugin is your project and I wouldn't hijack it - I'll try to have more constructive, bite-sized suggestions in the future :)

a+

-- p
main: Debian Jessie x64 + custom wxTrunk
jfouche
CodeLite Guru
Posts: 351
Joined: Mon Oct 20, 2008 7:26 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: script plugin

Post by jfouche »

Hello Eran,

I think that the first version of this plugin is ready, but I only have a Windows version compiling.
Do you think you (or someone else) can help me to make it work on Linux and Mac?
Jérémie
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: script plugin

Post by petah »

I just tried under Debian with:

Code: Select all

git clone -b LUA_SCRIPT git://github.com/jfouche/codelite luaCL
which builds & installs fine but when I run that CL version the Lua plugin doesn't even show up under the "manage plugins" list, nor do I find the plugin shared library in the install folder. Do I need to enable a specific cmake flag? If so, it'd help to have a little readme under the ./LuaScript folder.

If you and Eran could coordinate the github pull thing so the Lua plugin was always included when fetching CL's repo, with the Lua plugin build flag disabled by default so other users wouldn't hit any errors, then I would enable the Lua plugin build flag in my build procedure so I would test it every time I rebuild CL.

cheers,

-- p
main: Debian Jessie x64 + custom wxTrunk
jfouche
CodeLite Guru
Posts: 351
Joined: Mon Oct 20, 2008 7:26 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: script plugin

Post by jfouche »

Hi Petah, thanks a lot for your try

Well, as I only use Windows, I didn't manage cmake files at all. I suppose one have to update CMakefile.txt (the main one), and create one to the plugin, and (maybe) one to the Lua static lib...

On Windows, I compile Lua static lib using the provided makefile (I use a custom makefile project), which allow me to not manage the compile flags by myself.

[edit] : Here is the build process on Windows
- I created a lua project (custom build), which use the lua makefile in order to generate the static lib. It also copy the lua static lib to ..\..\lib\gcc_lib
- I created a LuaScript project (like all plugins), which add '../sdk/lua/src' to compiler search path, and the lua static lib to the linker.
- I added the 2 projects to the LiteEditor project dependancies (build order)

Let me know if those informations are ok to help you to make this plugin run
Jérémie
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: script plugin

Post by petah »

not sure how I can help further, I use CL under Debian & OSX but not Windows because my main customer only uses MSVC. I'm not sure if it's possible to build with CL and switch to VC's debugger at the same time. On Linux and OSX I use a custom makefile in CL's prebuild phase to build my Lua libs but on MSVC I have a custom SLN for that.

So far I have no idea how to reconcile both build procedures; maybe Eran can help you integrate the plugin into a cmake command? ;)

edit: nope it's too level for me; my *Nix/OSX build procedure doesn't go deeper than cmake :(

a+,

-- p
main: Debian Jessie x64 + custom wxTrunk
User avatar
eranif
CodeLite Plugin
Posts: 6367
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: script plugin

Post by eranif »

Hi,
The best way to integrate I will be to make some kind of generic metas ism to codelite cmake build system so users could provide a minimal plugin.cmake file

I will start looking into this and will let you know how we can proceed

Eran
Make sure you have read the HOW TO POST thread
jfouche
CodeLite Guru
Posts: 351
Joined: Mon Oct 20, 2008 7:26 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: script plugin

Post by jfouche »

Hi

Just to let you know :
- I installed a Ubuntu VM on my Win8 machine
- I updated CMake files to add the LuaScript plugin on Linux
- I succesfully build codelite
- ... And it crashes at startup :(

I'll need to debug codelite under linux... Is it possible to debug codelite with codelite under linux ? Any clue on how to do this ?
Jérémie
Post Reply