Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for luaL_Reg #4

Open
felipedaragon opened this issue Mar 23, 2014 · 7 comments
Open

Add support for luaL_Reg #4

felipedaragon opened this issue Mar 23, 2014 · 7 comments

Comments

@felipedaragon
Copy link

luaL_register is kind of working. I just don't know how to pass an array of luaL_Reg as the third parameter, so it is creating an empty table :)

@agladysh
Copy link
Member

Well, we need to research what does Emscripten require to pass arrays.

From a quick googling up, I've found this:

https://github.com/kripken/zee.js/blob/master/post.js#L2
https://groups.google.com/forum/#!topic/emscripten-discuss/Y4SS61n_fyc

Not too elegant and probably does need a wrapper.

I do not have time to look at this right now, unfortunately. But if you will send me a pull request, I'll review and accept it (don't forget to add yourself to AUTHORS in a separate commit, please).

Here is a place where to add the wrapper:

https://github.com/logiceditor-com/lua5.1.js/blob/master/src/js/lauxlib.h.js#L24

(You may find examples of wrappers below in the same file — look at macro definitions.)

@felipedaragon
Copy link
Author

Thanks! I will give a look at that

@agladysh
Copy link
Member

BTW, would be great if you'll be able to do some additional research on this. Maybe there is a less inelegant way.

@felipedaragon
Copy link
Author

Found a temporary workaround: call luaL_register with null and then pass the JS array using lua_pushcfunction and lua_setfield.
https://github.com/felipedaragon/lua_at_client/blob/master/js/latclient.js#L41
Usage example:
https://github.com/felipedaragon/lua_at_client#adding-a-library

@felipedaragon
Copy link
Author

A more advanced Lua<->JS bridge like the one you are thinking about implementing and similar to the one from lua.vm.js would make it so easy. Allow to call the JS objects directly from Lua, no need to register stuff with the C API.

@agladysh
Copy link
Member

agladysh commented Apr 2, 2014

Good that you've found a workaround!

Note that regardless of the existence of the bridge, the aim here is to support as much as Lua C API as possible, so support of luaL_reg is needed anyway.

@agladysh
Copy link
Member

agladysh commented Apr 2, 2014

BTW, the proper name is luaL_Reg, luaL_reg comes from compatibility mode with Lua 5.0.

@felipedaragon felipedaragon changed the title Add support for luaL_reg Add support for luaL_Reg Apr 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants