Execute a function given its name as a string!
Well, interesting problem. . . if you are not working with Lua. Some time ago, I developed a web interface that would interface with the camera I was working with. Being a fully autonomous system, Mipsee has limited ressources and PHP and databases were surely not the good solution for an embedded interface. I finally ended up with a Lua + HTML combo. The idea was to be able to start a computer vision application (face detection, blob tracking, . . .) and see the results in real time directly from the web interface. I searched for a simple way to detect and integrate new applications as they would be developed, without modifying the interface layer. In addition, those application would have variable inputs and outputs. My solution was to bind any new binary with an interface file that would define inputs and outputs for the given application.
And here came the issue : I would have the name of the binary as a string value. How to launch it when needed? Well, this could be a problem in C; but I was in Lua . . . Magic trick ! Problem solved in 3 simple lines of code :
if I want to execute param.
At first glance, I hated working with Lua which was way too messy and undocumented for me. But I’m still impressed by the capabilities of the language when correctly used. For those who don’t know Lua, this is a (portguese) language particularly used in video games. The user interface of WOW is for example fully developed in Lua (and I still wonder why . . .).
So, if some of you know any other advantage of working with Lua, let me know ;).