richardhundt / shine

A Shiny Lua Dialect
Other
231 stars 18 forks source link

Tips on embedding #84

Closed mindbound closed 6 years ago

mindbound commented 6 years ago

One of the strong points of Lua is that it's easily embeddable in C code. As far as I can see, there are no samples demonstrating embedded use of Shine.

What is the current state of support regarding this and what would be embedded Shine MWE look like? TIA.

rversteegen commented 6 years ago

You don't embed shine, you embed tvmjit, which is the virtual machine it runs on. tvmjit is just a modified version of luajit, and as far as I can tell, it is API and ABI compatible with luajit 2. There are a few extra functions in the API, eg the functions prefixed with 'tvm_' in this header: https://github.com/EitanR/tvmjit/blob/master/src/lauxlib.h

So, embedding it is identical to embedding luajit (except the library has a different name), which is ~identical to embedding lua. Include lua.h or luajit.h. Oh, but there is a new luaopen_tvm() function in lualib.h. You better call that, if you don't call luaL_openlibs().

mindbound commented 6 years ago

Thank you! That solves that.

rversteegen commented 6 years ago

For posterity: I finally noticed the documentation explaining tvmjit's extensions: https://github.com/richardhundt/tvmjit/blob/master/TP.md