L-28C writes:
Okay. I bin2c'd a luac'd file. I included the bin2c output in my C++
program, it gave syntax errors, an opening brace at the top and a
function call at the bottom. I removed the brace and cut/pasted the func
call to my C++ program. Here:
-- CODE/ --
#include <stdio.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include "mtx.luc.h" // bin2c file
int main()
{
lua_State *L = lua_open();
if (luaL_loadbuffer(L,(const char*)B1,sizeof(B1),"mtx.luc")==0)
lua_pcall(L, 0, 0, 0);
lua_close(L);
return 0;
}
-- /CODE --
I run the program but it gives no output. I'm on VC++ 2005 and it
compiles just fine.
Hmm, I use bin2c under Lua 5.0.3 and my C code looks roughly like this:
static int
open_mtx(lua_State *L)
{
#include "mtx.luc.h"
return 0;
}
int
main()
{
lua_State *L = lua_open();
open_mtx(L);
// ...
}
As far as I understand, bin2c creates a bit of code that can be
executed. So, it needs to be included somewhere in your C++ code
where you can then call it. That's why the #include is inside the
function. When you execute the code, then the compiled lua is run. I
guess you could simplify this even further (I don't because of lots of
other stuff in my code):
int main()
main()
{
lua_State *L = lua_open();
# include "mtx.luc.h"
// ...
}
The bin2c code references L, so you'll always have to make the
provision for L to be an available lua_State in the scope where you
include the bin2c code.
Robby
--
r dot raschke at tombob dot com