Sign in to follow this  
chophias

Grabbing output from lua script

Recommended Posts

Hello,

I 've got the following code
[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;
}
[/code]

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

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++?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this