Existence of a luabind::execute_file function ?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Existence of a luabind::execute_file function ?

Teto
Hi,

I started lua with luabind using it (or wanting to use it) as a C++
wrapper for lua. It allowed me to run my first lua script very quickly
(in a day) but also allowed me to avoid learning about lua inner
mechanisms (which was a bad thing, I had quite some difficulties to
getmyself learning the C api after that, I would recommand anyone to
start using lua without luabind and after some time to resort to
luabind)
I was wrong since many things are not possible with luabind alone. You
have to use lua functions. I was wondering to what extent luabind was
meant to complete lua. For example, is there any project to create a
function that replaces lua_loadfile || lua_pcall such as int
luabind::execute_file(const char*).
It would basically push the error callback function, load the file
chunk and then do an appropriate pcall and pop the callback function.
Does that go into the attribution of luabind ? or is luabind focusing
on binding only ?

Regards

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Existence of a luabind::execute_file function ?

Ryan Pavlik-4
While it's not as elegant, you could run the string "dofile('whatever')".  Or, just fork Luabind on Github and add the header you'd like yourself. I'd find it handy too.

Ryan

On Sun, Mar 13, 2011 at 5:58 PM, Teto <[hidden email]> wrote:
Hi,

I started lua with luabind using it (or wanting to use it) as a C++
wrapper for lua. It allowed me to run my first lua script very quickly
(in a day) but also allowed me to avoid learning about lua inner
mechanisms (which was a bad thing, I had quite some difficulties to
getmyself learning the C api after that, I would recommand anyone to
start using lua without luabind and after some time to resort to
luabind)
I was wrong since many things are not possible with luabind alone. You
have to use lua functions. I was wondering to what extent luabind was
meant to complete lua. For example, is there any project to create a
function that replaces lua_loadfile || lua_pcall such as int
luabind::execute_file(const char*).
It would basically push the error callback function, load the file
chunk and then do an appropriate pcall and pop the callback function.
Does that go into the attribution of luabind ? or is luabind focusing
on binding only ?

Regards

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user



--
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

[hidden email]
http://academic.cleardefinition.com
Internal VRAC/HCI Site: http://tinyurl.com/rpavlik

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Existence of a luabind::execute_file function ?

Teto
Just want to make sure before starting and after consulting the pil (http://www.lua.org/pil/25.2.html) and this page : http://www.corsix.org/content/common-lua-pitfall-loading-code, I should push the error handler function on the stack before loading file ( since loading file basically embeds the file into a function and pushes it onto the stack). Only then can I call pcall ?

So in lua:
-push error handler
-load file
-lua_pcall(L, 0,LUA_MULTRET, lua_gettop(L)-1)  ?

I could also use luabind::detail::pcall(L,1,0) so that the error handler is "lua_inserted" under the loaded file chunk ?


Nb: Just to be sure is answer http://www.luafaq.org/#T7.6 correct ? it looks correct to me but as it is an unofficial FAQ...

On Mon, Mar 14, 2011 at 3:43 AM, Ryan Pavlik <[hidden email]> wrote:
While it's not as elegant, you could run the string "dofile('whatever')".  Or, just fork Luabind on Github and add the header you'd like yourself. I'd find it handy too.

Ryan

On Sun, Mar 13, 2011 at 5:58 PM, Teto <[hidden email]> wrote:
Hi,

I started lua with luabind using it (or wanting to use it) as a C++
wrapper for lua. It allowed me to run my first lua script very quickly
(in a day) but also allowed me to avoid learning about lua inner
mechanisms (which was a bad thing, I had quite some difficulties to
getmyself learning the C api after that, I would recommand anyone to
start using lua without luabind and after some time to resort to
luabind)
I was wrong since many things are not possible with luabind alone. You
have to use lua functions. I was wondering to what extent luabind was
meant to complete lua. For example, is there any project to create a
function that replaces lua_loadfile || lua_pcall such as int
luabind::execute_file(const char*).
It would basically push the error callback function, load the file
chunk and then do an appropriate pcall and pop the callback function.
Does that go into the attribution of luabind ? or is luabind focusing
on binding only ?

Regards

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user



--
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

[hidden email]
http://academic.cleardefinition.com
Internal VRAC/HCI Site: http://tinyurl.com/rpavlik


------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Existence of a luabind::execute_file function ?

Tony Kostanjsek
hi,

here's what we do in our project, maybe it's of some help. It's deliberately only the doString part because file loading is a bit more involved (multiple possible locations). The return value/exception throwing combination is debatable.

best,
Tony

int State::doString(const std::string& inData)
{
  // execute the loaded file and handle errors
  int err = luaL_loadstring(state, inData.c_str());
  if(!err)
  {
    err = luabind::detail::pcall(state, 0, LUA_MULTRET);
  }
  if(err)
  {
    std::string errcode;
    switch(err)
    {
      case LUA_YIELD:errcode="LUA_YIELD";break;
      case LUA_ERRRUN:errcode="LUA_ERRRUN";break;
      case LUA_ERRSYNTAX:errcode="LUA_ERRSYNTAX";break;
      case LUA_ERRMEM:errcode="LUA_ERRMEM";break;
      case LUA_ERRERR:errcode="LUA_ERRERR";break;
      default:errcode="??";break;
    }
    std::string errstring;
    const char* errstringc = lua_tostring(state, -1);
    lua_pop(state,1);
    if (errstringc != NULL)
    {
      errstring = errstringc;
      throw LoadException(getScriptFilename(inData, inData) +" "+ errcode   +": "+ errstring);
    }
    else
    {
      throw LoadException(getScriptFilename(inData, inData) +" "+ errcode  +"");
    }
  }
  return err;
}



Von: Teto <[hidden email]>
An: Ryan Pavlik <[hidden email]>
CC: [hidden email]
Gesendet: Mittwoch, den 16. März 2011, 0:11:56 Uhr
Betreff: Re: [luabind] Existence of a luabind::execute_file function ?

Just want to make sure before starting and after consulting the pil (http://www.lua.org/pil/25.2.html) and this page : http://www.corsix.org/content/common-lua-pitfall-loading-code, I should push the error handler function on the stack before loading file ( since loading file basically embeds the file into a function and pushes it onto the stack). Only then can I call pcall ?

So in lua:
-push error handler
-load file
-lua_pcall(L, 0,LUA_MULTRET, lua_gettop(L)-1)  ?

I could also use luabind::detail::pcall(L,1,0) so that the error handler is "lua_inserted" under the loaded file chunk ?


Nb: Just to be sure is answer http://www.luafaq.org/#T7.6 correct ? it looks correct to me but as it is an unofficial FAQ...

On Mon, Mar 14, 2011 at 3:43 AM, Ryan Pavlik <[hidden email]> wrote:
While it's not as elegant, you could run the string "dofile('whatever')".  Or, just fork Luabind on Github and add the header you'd like yourself. I'd find it handy too.

Ryan

On Sun, Mar 13, 2011 at 5:58 PM, Teto <[hidden email]> wrote:
Hi,

I started lua with luabind using it (or wanting to use it) as a C++
wrapper for lua. It allowed me to run my first lua script very quickly
(in a day) but also allowed me to avoid learning about lua inner
mechanisms (which was a bad thing, I had quite some difficulties to
getmyself learning the C api after that, I would recommand anyone to
start using lua without luabind and after some time to resort to
luabind)
I was wrong since many things are not possible with luabind alone. You
have to use lua functions. I was wondering to what extent luabind was
meant to complete lua. For example, is there any project to create a
function that replaces lua_loadfile || lua_pcall such as int
luabind::execute_file(const char*).
It would basically push the error callback function, load the file
chunk and then do an appropriate pcall and pop the callback function.
Does that go into the attribution of luabind ? or is luabind focusing
on binding only ?

Regards

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user



--
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

[hidden email]
http://academic.cleardefinition.com
Internal VRAC/HCI Site: http://tinyurl.com/rpavlik



------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Existence of a luabind::execute_file function ?

Teto
thx a lot for your code, I've got it working.

On Wed, Mar 16, 2011 at 12:33 AM, Tony Kostanjsek <[hidden email]> wrote:
hi,

here's what we do in our project, maybe it's of some help. It's deliberately only the doString part because file loading is a bit more involved (multiple possible locations). The return value/exception throwing combination is debatable.

best,
Tony

int State::doString(const std::string& inData)
{
  // execute the loaded file and handle errors
  int err = luaL_loadstring(state, inData.c_str());
  if(!err)
  {
    err = luabind::detail::pcall(state, 0, LUA_MULTRET);
  }
  if(err)
  {
    std::string errcode;
    switch(err)
    {
      case LUA_YIELD:errcode="LUA_YIELD";break;
      case LUA_ERRRUN:errcode="LUA_ERRRUN";break;
      case LUA_ERRSYNTAX:errcode="LUA_ERRSYNTAX";break;
      case LUA_ERRMEM:errcode="LUA_ERRMEM";break;
      case LUA_ERRERR:errcode="LUA_ERRERR";break;
      default:errcode="??";break;
    }
    std::string errstring;
    const char* errstringc = lua_tostring(state, -1);
    lua_pop(state,1);
    if (errstringc != NULL)
    {
      errstring = errstringc;
      throw LoadException(getScriptFilename(inData, inData) +" "+ errcode   +": "+ errstring);
    }
    else
    {
      throw LoadException(getScriptFilename(inData, inData) +" "+ errcode  +"");
    }
  }
  return err;
}



Von: Teto <[hidden email]>
An: Ryan Pavlik <[hidden email]>
CC: [hidden email]
Gesendet: Mittwoch, den 16. März 2011, 0:11:56 Uhr
Betreff: Re: [luabind] Existence of a luabind::execute_file function ?

Just want to make sure before starting and after consulting the pil (http://www.lua.org/pil/25.2.html) and this page : http://www.corsix.org/content/common-lua-pitfall-loading-code, I should push the error handler function on the stack before loading file ( since loading file basically embeds the file into a function and pushes it onto the stack). Only then can I call pcall ?

So in lua:
-push error handler
-load file
-lua_pcall(L, 0,LUA_MULTRET, lua_gettop(L)-1)  ?

I could also use luabind::detail::pcall(L,1,0) so that the error handler is "lua_inserted" under the loaded file chunk ?


Nb: Just to be sure is answer http://www.luafaq.org/#T7.6 correct ? it looks correct to me but as it is an unofficial FAQ...

On Mon, Mar 14, 2011 at 3:43 AM, Ryan Pavlik <[hidden email]> wrote:
While it's not as elegant, you could run the string "dofile('whatever')".  Or, just fork Luabind on Github and add the header you'd like yourself. I'd find it handy too.

Ryan

On Sun, Mar 13, 2011 at 5:58 PM, Teto <[hidden email]> wrote:
Hi,

I started lua with luabind using it (or wanting to use it) as a C++
wrapper for lua. It allowed me to run my first lua script very quickly
(in a day) but also allowed me to avoid learning about lua inner
mechanisms (which was a bad thing, I had quite some difficulties to
getmyself learning the C api after that, I would recommand anyone to
start using lua without luabind and after some time to resort to
luabind)
I was wrong since many things are not possible with luabind alone. You
have to use lua functions. I was wondering to what extent luabind was
meant to complete lua. For example, is there any project to create a
function that replaces lua_loadfile || lua_pcall such as int
luabind::execute_file(const char*).
It would basically push the error callback function, load the file
chunk and then do an appropriate pcall and pop the callback function.
Does that go into the attribution of luabind ? or is luabind focusing
on binding only ?

Regards

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user



--
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

[hidden email]
http://academic.cleardefinition.com
Internal VRAC/HCI Site: http://tinyurl.com/rpavlik




------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software
be a part of the solution? Download the Intel(R) Manageability Checker
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user