in my current project I have to deal with a graph where each node should provide the capability to run different user defined behaviours on given triggers. An XML definition could (for example) look like this:
<node name="node 1">
<scripts source="function onEnter() print('do something') end"/>
<node name="node 2">
<scripts source="function onEnter() print('do something different') end"/>
So as you can see the function onEnter (which will be called when entering the node) appears two times with different implementations through these scripts. While I could solve the problem by having one state per object, this would mean to have a lot of states spread throughout the application which does not seem optimal to me.
I was also thinking to parse the scripts before sending them to Lua (through luaL_loadstring) and replace all functions with dynamically generated functions (e.g. onEnter<UID> instead of onEnter) but somehow I got the feeling that there must be a better solution for this problem.
I'd really be thankful for any guidance you can give me.