Advertisement

Grabbing output from lua script

Started by October 08, 2011 07:51 PM
-1 comments, last by chophias 13 years, 2 months ago
Hello,

I 've got the following code

extern "C"
{
#include "lua/lua.h"
#include "lua/lauxlib.h"
}
#include "luabind/luabind.hpp"
#include <iostream>
using namespace std;
void teller()
{
int i = 0;
for(i=0;i<10;i++)
{
cout << i << ",";
}
}

int main()
{
//create a lua state
lua_State* pLua = lua_open();

//open luabind
luabind::open(pLua);

/* Register functions and classes with luabind here */
luabind::module(pLua)
[
luabind::def("teller", &teller)
];

/* load and run the script here */

luaL_dofile(pLua, "script1.lua");

//luaL_dostring(pLua, "teller()");

//tidy up
lua_close(pLua);

return 0;
}


script1.lua

print("[lua]: About to call the C++ teller() function")
teller()


If I uncomment //luaL_dostring(pLua, "teller()"); , then i get the output from the teller() function in my console window,
If I use luaL_dofile(pLua, "script1.lua"); , then i dont get anything in my console window, just "process returned 0, 0x0)

Im using lua 5.1.4 & luabind 0.9.1

Anyone can tell me how to grab the output from a .lua file that was executed from inside c++?

This topic is closed to new replies.

Advertisement