Suppose I have a global function called foo() which I've implemented internally outside of Lua and exposed to the user. Ideally I'd like the user's IDE to be aware of this function for things like autocomplete. The closest thing that comes to mind would be a header file for C/C++, where the function is declared without being defined.
Does Lua have any support for this?
There is no cross IDE mechanism for this in Lua.
There is no way to declare a function prototype in Lua. You can only define function values. So unless you don't provide your functions as Lua code no IDE will be able to parse them for autocompletion. So you would have to provide IDE-specific autocomplete files for your API.
Most Lua development is probably done in a simple text editor anyway.
Provide a good documentation for your API and any Lua developer using it will be happy.
As Piglet mentioned there is no out-of-the-box solution for Lua that works across all IDEs. However, I found a typed variant of Lua called Teal which has support for declaration files. Teal seems fairly analogous to Typescript.
Related
I've created a large library in Dart that need to be called from JavaScript. I'd like to avoid using JS Interop if possible. Can I use the Dart Dev Compiler to do this?
Is it possible to take the JavaScript code generated by DDC and easily call it directly?
I'm guessing you'll need some #JS because otherwise, the tree-shaking will likely remove any need for the very entrypoints you want, and the code won't even be there.
I am new in lua,need basic type of help.After install BabeLua extension on Visual Studio,they indent and everything for me. Want to work with SciTE IDE, It's a pain in having to indent my code all the time so looking a way which can format my lua code manually and automatically.
Note: try to use source-code-formatter and beautifier.I failed to use them in my lua module.How to use them in lua?They are workable or not?
I think the idea with those beautifiers you reference is that you can run them as an external program: save your current buffer to a file, run through the filter to beautify, then read the result back into the current buffer in SciTE.
I can vouch for the second program as I used it in the past to re-indent some of my code; I ended up re-implementing it in Perl as it didn't handle all the cases I was interested in.
If you want to integrate it into SciTE, you can probably strip some of the io functions and just use functions to read buffer content in SciTE (like GetLine) and then modify the indentation (probably using GetLineIndentation and SetLineIndentation). I've implemented a very similar logic in my Lua IDE, which is using the same editor component that is used in SciTE.
I got code::blocks as my C/C++ compiler along with C++ for dummies, but my only problem is with a obscure scripting language that I have never heard of before; "Squirrel". Is it possible to change the scripting language of code::blocks to something more familiar to me, like lua?
It seems doable in theory. Whether it is doable in practice, hard to say. Here is what you would need to do:
create a folder src/sdk/scripting/lua in which you put the Lua interpreter (+ Lua libraries like io, math etc) source code and create project file for it
create a folder in src/sdk/scripting/lua_bindings where you put your Lua bindings: the C++ files that allow Lua scripts access to the host application. I recommend you use a tool like SWIG to generate them (codeblocks uses SqPlus). This involves determining what code-blocks functions/classes you want to export, creating one or more .i files, running SWIG on them, put the generated files going into "lua_bindings"; create a DLL project for the bindings
Create a src/lua_scripts in which you put the Lua equivalent of scripts found in src/scripts; or rather, a subset of those scripts, because it is unlikely you will want to export to Lua everything that is available via Squirrel if you're just following examples from a book
Find where Squirrel interpreter is instantiated in codeblocks and where RegisterBindings is called; replace it with instantiation of a Lua interpreter and call your luaopen_codeblocks which you will have created via SWIG (no need for a RegisterLuaBindings if you use SWIG, it does that for you)
Find where the various scripts are called by codeblocks (see http://wiki.codeblocks.org/index.php?title=Scripting_Code::Blocks). Call the equivalent Lua scripts (which are in lua_scripts -- you'll surely have to copy this to the installation folder for code-blocks). For example the startup.script, which is the Squirrel script that codeblocks automatically looks for at startup, is run by the following code in src/src/app.cpp:
// run startup script
try
{
wxString startup = ConfigManager::LocateDataFile(_T("startup.script"), sdScriptsUser | sdScriptsGlobal);
if (!startup.IsEmpty())
Manager::Get()->GetScriptingManager()->LoadScript(startup);
}
catch (SquirrelError& exception)
{
Manager::Get()->GetScriptingManager()->DisplayErrors(&exception);
}
I think that's about it.
Naturally based on how extensive your scripting is, you may cut some corners, but as you can see, this is not for the faint of heart!
Is there a documentation for ocropus?
I am looking for an explanation for the functions like:
make_SegmentPageByRAST():
segment()
RegionExtractor():
setPageLines()
extract()
Thank you.
A requirement of Lua API for OCRopus has been filed in the bug-tracker list of the project.
They will soon be releasing this documentation in the next beta release(expected).
First, note that you can use the command line tools without actual Lua programming.
A good place to see how to use ocroscript is to look at the test cases in
ocroscript/tests and the command line driver scripts in ocroscript/scripts.
Note: The Lua bindings follow the C++ API very closely (the binding is mostly
automatic), so C++ and Lua documentation are pretty much the same problem.
Years ago, I wrote a code template that took a few simple parameters (points) and produced a class skeleton. Since some of the method bodies had code in them, I couldn't call InvokeClassCompletion and just placed the implementations with the declarations (user had to move them).
It has occurred to me that I can write a code template script engine to insert these methods in the correct position, but I don't see how I'm supposed to navigate the file. There are declarations for IOTAEditReader and IOTAEditWriter in ToolsAPI.pas, but I'm guessing there is a step missing - certainly I don't need to manually parse the Delphi code just to find the implementation section?
Does anyone have experience with it?
The IDE has plenty of parsers in it, but not one is made available for IDE plugins (ToolsAPI). So you have to write your own parser or use an existing one like http://delphiblog.twodesk.com/using-the-castalia-delphi-parser
You might find that GExperts or CNPack contains almost all the code you need, in one of its editor wizards.
If not, then, those two are the best reference I know for writing IDE plugins. As far as writing parsers, see Andreas' answer.
If you just want better code templates, you could consider buying Castalia, as it has an improved code template feature over the builtin delphi IDE plugin features. Castalia internally uses the Castalia delphi parser mentioned by andreas. It's quite good.