How does the lua plugin work

Script Plugin (LUA) development forum
jfouche
CodeLite Guru
Posts: 350
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 » Thu Jan 30, 2014 8:25 pm

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

Jarod42
CodeLite Expert
Posts: 176
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 » Fri Jan 31, 2014 2:26 pm

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: 350
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 » Mon Feb 03, 2014 12:03 am

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

Jarod42
CodeLite Expert
Posts: 176
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 » Wed Feb 05, 2014 4:08 pm

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 » Sat Feb 08, 2014 12:21 pm

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