How to use Metalua with an embedded Lua?

154 views
Skip to first unread message

Jaco

unread,
Nov 17, 2011, 9:59:15 AM11/17/11
to met...@googlegroups.com
We are using Lua embedded into our native C++ application. I can see how to use Metalua with the standalone "lua.exe" application with the command-line arguments. However, it's not obvious for me how to use it in the embedded case. 

Could you maybe provide an example or some guidelines on how to run metalua programs from within an embedded Lua instance?

Fabien

unread,
Nov 17, 2011, 10:22:11 AM11/17/11
to met...@googlegroups.com
The simplest and most efficient way is to precompile your lua sources into bytecode when you build your app; you then simply load this regular Lua bytecode in your regular lua 5.1 VM, at runtime.

If it is mandatory for you to compile Metalua sources on-the-fly, then put the metalua.* libraries in a place accessible to your LUA_PATH, and use mlc to compile and run your metalua code

require 'metalua.compiler' -- load, among others, mlc
f = mlc.luafile_to_function [[c:\tmp\a_metalua_source_file.mlua]]
g = mlc.luastring_to_function [[ inc=|x| x+1; assert(inc(1)==2) ]]
f()
g()


Jaco

unread,
Nov 18, 2011, 3:00:32 AM11/18/11
to met...@googlegroups.com
Thanks, we require the on-the-fly method, so your example is of great help
Reply all
Reply to author
Forward
0 new messages