Hi Sergey,
> Your suggestion to make a hook is a way to go - a new MG_LUA event could be introduced, and event handler can add whatever variables to the new Lua state.
I looked into it a bit, and here is how I think one could do it:
- Add a MG_LUA_SETUP event type.
- Add a pointer to the Lua state to mg_connection, because otherwise the event handler can't access it.
- Add a call_user() call to prepare_lua_environment. The return value can be ignored.
- Expose the Lua support functions (reg_string etc.) in mongoose.h. (I haven't looked into how embedding in Lua works, I'm just saying this based on what I see in prepare_lua_environment.)
Does that make sense?
Jurie
> On Thu, Mar 6, 2014 at 2:11 PM, Jurie Horneman <
jurie.h...@gmail.com> wrote:
> I was wondering if there is a way to pass arbitrary information from C++ through Mongoose so it's accessible in Lua? I want to pass some variables to Javascript and just passing them as literal Javascript in a script tag is a technique I find often works well (as opposed to asking for the data using a JSON call).
>
> (Example: My C++ code has a variable magic_string which contains "Mongoose rocks". And I want to pass that to my Javascript code, so I want to generate this using Lua:
>
> <script>
> var magic_string = "Mongoose rocks";
> </script> )
>
> I looked at the manual and the code but I can't figure out if there is a way. Short of using environment variables I can't think of a way of doing it from Lua either.
>
> A way of hooking into prepare_lua_environment (e.g. passing in a list of strings) might do the trick. (No idea if that's the Mongoose way, sorry.)
>
> Thanks in advance for any help.
>
> Jurie
>
> --
> You received this message because you are subscribed to the Google Groups "mongoose-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
mongoose-user...@googlegroups.com.
> To post to this group, send email to
mongoos...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/mongoose-users.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "mongoose-users" group.
> To unsubscribe from this topic, visit
https://groups.google.com/d/topic/mongoose-users/tz-MjbEw-pY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
mongoose-user...@googlegroups.com.