Autocompletion generator

Hi,

Inspired by the “ToDoxHook.lua” file, I’ve prepared generator for an auto-completion list of Lua functions/properties for the MIT licensed Zerobrane IDE and maybe eventually other IDEs.

Before sending/committing to you, I had few question about the logic and possibilities:

[ul][li]Should I exclude the 1st level of auto-completion for classes available in the Global Properties? (ex.: “audio” only would be available in the list and “Audio” would not be visible but will be used as reference for this class auto-completion)[/li]
[li]Does the Lua function reflect new object creations via Object:new() or only Object() directly?[/li]
[li]Along with the constructors, is there destruction functions in Lua? (does ~Object() is possible in Lua? If not, does Object:destroy() exists? Else-wise, returning an object as “nil” will be garbage collected?)[/li][/ul]

I also plan later to give a try (unless aster goes ahead :smiley: ) to fetch description comments (///) from the C++ equivalent functions using the header includes from the packages and match them with the Lua function for the tool-tip description from the auto-completion in Zerobrane.

Thanks!

Welcome aboard!

The construction / destruction mechanisms in Lua scripting are documented here: (look at the end of the page) urho3d.github.io/documentation/a00017.html

Pull request sent!

I’ve discussed with the author from Zerobrane Studio for helping me fix/confirm some issues and he seemed to find Urho3D project quite interesting, so it might help for publicity. :wink:

I also suggested to send him a pre-generated Lua API once the next release from Urho3D will be launched.

Let me know if you see something wrong, thanks!

[size=85][color=#FF0000]*[/color] Please note that Zerobrane Studio 0.40 doesn’t work properly with Object() constructor but will be fixed in next release (“master” worked properly)[/size]

Great job silverkorn :wink:

Do we need to setup a Zerobrane config file to be able to launch lua files with Urho3DPlayer from within the IDE?
Thanks

Yes, we currently need to setup an interpreter in Zerobrane.

Here’s how it could be done (Based on Zerobrane Studio in “master” branch [size=85][https://github.com/pkulchenko/ZeroBraneStudio/tree/master][/size]):
[ul]
[li]For the moment since it’s not directly implemented yet, copy the “love2d.lua” within the “interpreter” folder;[/li]
[li]Rename this file to “urho3d.lua”;[/li]
[li]In the file, rename all “love2d” to “urho3d”, “Love2d” to “Urho3D” and finally “love” to “urho3d” (some case-sensitivity may vary);[/li]
[li]On line #26, replace the 2 last executable names to “Urho3DPlayer.exe” and “Urho3DPlayer”;[/li]
[li]Add where your Urho3DPlayer resides in the default variables on lines #16 to #19 (or simply add this path in your PATH environment if you’re familiar with it);[/li]
[li]Remove/Comment the condition from line #36 to #39;[/li]
[li]Change line #46 and #47 to local cmd = (’"%s" “%s” %s’):format(urho3d, wfilename:GetFullName(), params and " "…params or “”);[/li]
[li]Open Zerobrane Studio and setup a project directory by clicking on the “…” button on the left panel (Urho3D’s “./Bin/Data/LuaScripts” for exemple);[/li]
[li]Change the the interpreter to Urho3D in “Project” -> “Lua Interpreter” -> “Urho3D”;[/li]
[li]Open a Lua file then launch it “Project” -> “Run” (or F6) or with Scratchpad (*not tried yet, should run directly modifications without restarting the player) “Project” -> “Run as Scratchpad” (or Ctrl-F6).[/li][/ul]

These steps are not final neither 100% guaranteed to work so keep in mind that I’m planning to send an API and interpreter setup to Zerobrane Studio’s repository once the next Urho3D release will be out. You will be able after to replace the API file with one generated manually from a future version and/or the master branch.

Until the next release, I’ll work on a better interpreter configuration setup and probably setting a reflection of the C++ Doxygen description into the “ToZerobraneStudioHook.lua” generator. :slight_smile:

Many thanks silverkorn :smiley:

For now it seems that Scratchpad doesn’t work as is.

Thanks for sharing this, silverkorn. Just try it with the ToZerobraneStudioHook.lua and I am loving it already. BTW, while reviewing the hook, I notice the printFunction() does not include any constructors. Is that intentional? Otherwise, the ToDox hook and ToZero hook could share a large chunk of codes and only differs in outputting logic in the end. Probably could use ‘require’ statement to include the shared chunk to avoid code repetition? Also, saw your TODO comment. Do you plan to put those doxygen comment to ToDox hook as well when it happens?

Yes, Zerobrane Studio doesn’t support it properly and, as I understood from the document sent by cadaver, we should not call “Object:Object()” in Lua for construction, so the latest Zerobrane Studio (currently on “master” branch) supports “Object()” as an object/class reference.
Otherwise, “new” and “delete” methods are used as alternative, but these needs to be managed manually, they will not be garbage collected by Lua, only the “Object()” constrcutor will be.

Why not? To be honest, I’ve copied the 1st “ToDoxHook.lua” that was created to have the freedom to modify it without feeling restricted… Was it by you or Aster?
Feel free to edit it if needed.

Sure. I’ll start with the Zerobrane hook then I could fit and adjust it in the ToDox hook.

Good job!

You can require ToDoxHook in your lua, then rewrite classPackage:print and these writeXXX funtions, I think it will work well.

Ok, I’ve applied it. I just needed to set first variables as global in “ToDoxHook.lua” and it seems to work.
I guess I’ll create the description’s fetch/map in the “ToDoxHook.lua” to consider it as the default/master script.

Btw, I’ve noticed that I was added in the credits list, thanks for that!
You can change it to my full name, I realized that you took the one from my profile and I just updated it! :wink:
Thanks!

Nice! Your PR has been merged now.

Hi guys, little update.

I had time to play with the description extractor recently.

The general results seems good but it’s a bit clunky since it’s like I had to rewrite the Classes/Functions/Properties generator (ie, many regular expressions and cross-platform (to test) currently working directory workaround).

It needs some adjustments to fit in both “Dox” and “Zerobrane” output but I guess the hardest part is now behind. :smiley:

I’ll probably need a confirmation when done on it’s operation on Unix/BSD platforms.

Thanks!

Hi!
I started a similar project a few weeks ago to provide autocompletion in Eclipse LDT (github.com/Gotusso/UrhoLDT)
Too bad I didn’t saw this before, I wouldn’t have started that project :stuck_out_tongue: I should check your code and try to merge as much code as possible.
On the other hand, I would like to debug the Lua code on the IDE, so I’m modifing the player to accept an ‘-e’ parameter, as Eclipse LDT and Zerobrane uses it to wire-up some code for debugging. Have you looked something about that?
Cheers

Sorry gotusso :wink:

No, I didn’t have time to look at this, this month is unfortunately quite charged on my side and I’m having headaches with the description fetching. (The funny thing is, in the end if it works well, it could maybe replace the entire parsing mechanism from “tolua++” on package and header files with a standalone script) :confused:

Otherwise, got on with it! I guess this is the missing piece to inject code for live coding (scratchpad) and debugging with Zerobrane Studio.
I would maybe suggest to make it possible by default on the debug build (with Lua/LuaJIT) to avoid code injection on a final product for security purpose.

Hey guys,

I’m in running some questionable situations.

I want to map the description depending on the Class -> Function/Property name -> Parameters for splitting overloading function.
Here’s some example of what my debug print returns:

[code]Current Params: const String& name, unsigned char layer, bool looped, float fadeInTime = 0.0f
Name: Play
ok (name = “Play”, type = “functions”, className = “AnimationController”)
Class: AnimationController = AnimationController
Element: Play = Play
Func1 Param: “const String”, “&”, “name”, ""
Func1 Param: “unsigned”, “”, “char”, ""
Func1 Param: “bool”, “”, “looped”, ""
Func1 Param: “float”, “”, “fadeInTime”, "0.0f"
Func2 Param: “const String”, “”, “name”, ""
Func2 Param: “char”, “”, “layer”, ""
Func2 Param: “bool”, “”, “looped”, ""
Func2 Param: “float”, “”, “fadeInTime”, "0.0f"
Is same element? False

Current Params: const String& fileName = String::EMPTY
Name: ApplyMaterialList
ok (name = “ApplyMaterialList”, type = “functions”, className = “StaticModel”)
Class: StaticModel = StaticModel
Element: ApplyMaterialList = ApplyMaterialList
Func1 Param: “const String”, “&”, “fileName”, "String::EMPTY"
Func2 Param: “const String”, “”, “fileName”, "String::EMPTY"
Is same element? False[/code]
[size=85](Func1 Param = Header function’s parameter, Func2 = Package function’s parameter)[/size]

It says that the function is not the same due to the pointer/reference and it definitively is the case from what’s I’ve seen in the package file VS the header file.

Similarly, I have a missing but “defaulted” argument like this:

Current Params: Model* model, bool createBones = true Name: SetModel ok (name = "SetModel", type = "functions", className = "AnimatedModel") Class: AnimatedModel = AnimatedModel Element: SetModel = SetModel Func1 Param: "Model", "*", "model", "" Func1 Param: "bool", "", "createBones", "true" Func2 Param: "Model", "*", "model", "" Is same element? False

Is it intentional?
Should I ignore those cases as they are quite specific or make an additional possibility if it’s a “const String” against “const String&”?

Thanks!

Both of these are intentional. Passing strings as const String instead of const String& is an artifact of the Lua bindings mechanism. Aster will know this better. And sometimes “advanced” default-valued parameters that only make sense in internal engine use are left out from the script bindings, like the createBones parameter. In that case it’s also to allow turning the SetModel function into a property setter.

Hi,

Because String is a custom class, if we binding it to Lua, all string operate are very difficult. Lua’s string functions are very strength. So we directly mapping String to Lua string. These are same mapping between Vector and Lua table.

I think you can ignore constant, reference and default value, just compare argument types.

Noted!

What about this?
StringHash == const String? [size=85]
(I’ve changed the “Func” printing name to be more relevant)[/size]

Current Params: StringHash eventType, VariantMap& eventData Name: SendEvent ok (name = "SendEvent", type = "functions", className = "Object") Class: Object = Object Element: SendEvent = SendEvent FuncHeader Param: "StringHash", "", "eventType", "" FuncHeader Param: "VariantMap", "&", "eventData", "" FuncPackage Param: "const String", "", "eventName", "" FuncPackage Param: "VariantMap", "*", "eventData", "0" Is same element? False

Also, shall I embed “unsigned” with next word as a type (or simply ignore it) and guess that “unsigned char” == “char”?

Current Params: const String& name, unsigned char layer, bool looped, float fadeTime = 0.0f Name: PlayExclusive ok (name = "PlayExclusive", type = "functions", className = "AnimationController") Class: AnimationController = AnimationController Element: PlayExclusive = PlayExclusive FuncHeader Param: "const String", "&", "name", "" FuncHeader Param: "unsigned", "", "char", "" FuncHeader Param: "bool", "", "looped", "" FuncHeader Param: "float", "", "fadeTime", "0.0f" FuncPackage Param: "const String", "", "name", "" FuncPackage Param: "char", "", "layer", "" FuncPackage Param: "bool", "", "looped", "" FuncPackage Param: "float", "", "fadeTime", "0.0f" Is same element? False

Sorry for those questions, unfortunately I’m not an usual C/C++ programmer :confused:

signed vs unsigned denotes whether there is a bit reserved for the negative or positiveness of a number. Unsigned has no negative value so it can use that extra bit for getting bigger numbers or limiting the domain of a number to only positive ones. I am guessing we are using an unsigned char for cheesing an 8 bit number. Integers are 32bit. I can’t get much further into detail since alas I am no c++ programmer myself.

@silverkorn If you like, you can put your project to github. So other people can contribute to it.