WeaselGames / godot_luaAPI

Godot LuaAPI
https://luaapi.weaselgames.info
Other
371 stars 28 forks source link

Is it possible to include the LPEG library? #100

Closed NationalityNZ closed 6 months ago

NationalityNZ commented 1 year ago

Is your feature request related to a problem? Please describe. I'm using Godot to build a UI for a Lua program. LPEG is one of the necessary components of that program. Because lpeg (https://www.inf.puc-rio.br/~roberto/lpeg/) is a C extension to lua, it is not possible to simply include Lua code without rebuilding.

Describe the solution you'd like For LPEG to be one of the included libraries. LPEG is just generally excellent and useful. It is a powerful pattern-matching tool that outstrips anything included in Godot.

Describe alternatives you've considered There is a LPEG library written in pure Lua, (https://github.com/pygy/LuLPeg) but it is much slower than the c extension.

Additional context Thank you for your time and for the extension.

Trey2k commented 1 year ago

Hello, love the idea of using godot for your UI in a lua app! So I will have to test to be certain. But I belive you can load the dynamic library with the require method from the package library. There is a more detailed explanation on how this could be done here https://github.com/WeaselGames/godot_luaAPI/issues/72#issuecomment-1455079741

Edit: Ofcourse binding the package library escapes the sandbox so use caution with this method. If the sandbox must be maintained then we would need to find another solution.

NationalityNZ commented 1 year ago

Thanks for your super rapid reply!

With the particular application I want to use it for, sandboxes aren't really an issue. My project is a text adventure engine and the vm is coded in lua, it does load lua user scripts but it uses its own sandbox to do that. LPEG is necessary to parse user input and to process macros in user scripts. However, I can definitely see an application in loading lpeg at the godot layer, so you might consider implementing a way to load user libraries from an internal method anyway.

I'll try the method outlined in the reply you highlighted, but I'll admit I didn't 100% grok it. I'm still new to the c aspects of lua and how the dynamic library system works.

I appreciate your hard work.

Trey2k commented 1 year ago

However, I can definitely see an application in loading lpeg at the godot layer, so you might consider implementing a way to load user libraries from an internal method anyway.

I agree that this still could be a useful addition to load a external lib while maintaining the sandbox. Something to look into.

Trey2k commented 1 year ago

Out of curiosity, were you able to get LPEG loaded?

NationalityNZ commented 1 year ago

I was side-tracked by real-life stuff, so I didn't really have a chance to check. When I do try it, I'll let you know.

Trey2k commented 1 year ago

While looking into impmenting a method to load native lua modules I ran into issues with missing symbols. After some digging around I've found a related thread in the Lau mailing list http://lua-users.org/lists/lua-l/2019-02/msg00078.html

Still need to test further, but if i understand it correctly it looks like either the module would need to link to lua dynamically or the lua module (in this case lpeg) would need to also link to lua statically.

If I manage to get this working the plan is to expect either a string or FileAccess object in the array of library's passed to bind_libraries. In the case of a file access it will expect it to be a native librarie.

GokuHiki commented 11 months ago

How can I include LPEG into lua build with Godot? Dynamic lua binary module not really work because a lot of dependency! Can Godot LuaAPI still work after export to other target platform? Thank you and regards!

Trey2k commented 11 months ago

How can I include LPEG into lua build with Godot?

This should be possible with a few scons and c++ edits. The idea would be to make sure the source files for the library are built into the module builds. Then you would need to modify the bind_libraries function to include the new library.

GokuHiki commented 11 months ago

Well... It is too embarrassing but I don't know how to do this. Can you support add LPEG library option in build with scons flag like INCLUDE_LPGE?

Thank yoy and regards!

Trey2k commented 11 months ago

It is too embarrassing but I don't know how to do this.

No reason to be embarrassed. Not everyone is familiar with C and C++.

Can you support add LPEG library option in build with scons flag like INCLUDE_LPGE?

This could potentially happen. My concern is I would then have to add it as a git sub module under external. And when someone needs another library now that has to be added and so on....

This may be able to be done via some simple code gen though so I will look into that route.

Trey2k commented 6 months ago

Support for this should of been added with #178. If any issues arise feel free to reopen.