How does the lua plugin work

Script Plugin (LUA) development forum
jfouche
CodeLite Guru
Posts: 351
Joined: Mon Oct 20, 2008 7:26 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

How does the lua plugin work

Post by jfouche »

Hello,

I worked a little bit on the plugin, and I can provide some kind of user manual here :

0 - How can I get it
You can clone my repository :https://github.com/jfouche/codelite, and checkout the LUA_SCRIPT branch. You can also add a remote on my repository, and fetch it, if you already have a repository which fetch Eran's one. For the moment, it only works on Windows as I don't have linux or mac machines. You can compile codelite, as the wiki explains it : http://codelite.org/Developers/Windows

1 - How to manage the scripts
You can see a script tab on the workspace view. On this tab, you have 4 commands
* Add script : use it to add a script to codelite. This script will be available on the script list under the toolbar.
* Run script : to run the selected script. You can also run a script by double clicking on the script item in the list.
* Edit script : you can edit a script by clicking on the button. While it's modified, you just have to save it, it will be updated, and ready to run with the new script content.
* Delete script : well, if you don't need a script anymore

2 - Available API
Codelite API is availble through the cl_manager variable, and here are the current implemented methods
* IManager:GetActiveEditor() : return the current editor, or nil
* IManager:NewEditor() : return a new editor. It will create an new "untitled" editor.
* IManager:GetWorkspace() : return the workspace, or nil if none is open
* IEditor:GetEditorText() : return the whole editor content
* IEditor:SetEditorText(string) : replace the editor content with the provided string
* IEditor:GetSelection() : return the current selection
* IEditor:ReplaceSelection(string) : replace the current selection with the provided string
* IEditor:AppendText(string) : append string at the end of the editor
* Workspace:GetActiveProjectName() : return the name of the active project
* Workspace:GetProjectList() : return a list of project names
* Workspace:FindProjectByName(string) : return the project named by the provided string, or nil
* Project:GetName() : return the name of the project
* Project:GetFiles() : return a list of project files, with absolute path

3 - A sample, please...
ok, here is one which comment the current selection if any (comment.lua) :

Code: Select all

editor = cl_manager:GetActiveEditor()
if editor then
	sel = editor:GetSelection()
	if #sel ~= 0 then
		text = "/* " .. sel .. " */"
		editor:ReplaceSelection(text)
	end
end
Feedback is welcome,
Enjoy
Jérémie
User avatar
Jarod42
CodeLite Expert
Posts: 240
Joined: Wed Sep 30, 2009 5:54 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: How does the lua plugin work

Post by Jarod42 »

Do you know tolua++.

It may help you to port Codelite to lua easily.
(I would avoid to parse codelite headers directly but provide a custom subset).
jfouche
CodeLite Guru
Posts: 351
Joined: Mon Oct 20, 2008 7:26 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: How does the lua plugin work

Post by jfouche »

Hello Jarod,

I download tolua++, but I was not able to compile it with mingw under Win8 :(
Moreover, I don't know if this is worth it (lua binding is simple to implement).
I think I need to see it running to understand what is great with this tool.
Jérémie
User avatar
Jarod42
CodeLite Expert
Posts: 240
Joined: Wed Sep 30, 2009 5:54 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: How does the lua plugin work

Post by Jarod42 »

tolua++ has not been ported to lua 5.2+ :-/

It did the binding for you according to a header...

I don't find an equivalent with a quick search (I found libraries which ease the code to write, but not write the code for you :-/).
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: How does the lua plugin work

Post by petah »

I think whether a 3rd party Lua binder is worth the effort depends on how many different C++ function signatures you need to interface Lua with... and how well the 3rd party library is supported. IMO it's not a good sign that it doesn't support Lua 5.2

cheers,

-- p
main: Debian Jessie x64 + custom wxTrunk
Post Reply