error/exception hadling in luabind

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

error/exception hadling in luabind

Domino-2

Hello,

 

My question is how to handle errors that tells something more than “lua runtime error”. In my code I need multiple scripts for the single lua state that shouldn’t know about each other so I’m using lua code to load the scripts (the code comes from this list by the way). Below is the example of the code that I have problem with:

 

// C++

std::string scriptLoaderCode("function scriptloader (scriptTable, scriptname)\n \

                              local mt = {__index=_G} \

                              setmetatable(scriptTable, mt) \

                              local chunk = loadfile(scriptname) \

                              setfenv(chunk, scriptTable)  \

                              chunk() \

                              end");

 

luaL_dostring(pLua, scriptLoaderCode.c_str());

  {

    luabind::object newtable = luabind::newtable(pLua);

    try

    {

      luabind::call_function<void>(pLua, "scriptloader", newtable, "test3.lua");

    }   

    catch (luabind::error e)

    {

      std::cout << "exception:" << std::endl;

      std::cout << "\t" << e.what() << std::endl;

    }

  }

 

And the lua code (just a simple test from documentation):

 

// lua

 

class 'lua_testclass'

 

function lua_testclass:__init(name)

    self.name = name

end

 

function lua_testclass:print()

    print(self.name)

end

 

class 'derived' (lua_testclass)

 

function derived:__init() super('derived name')

end

 

function derived:print()

    print('Derived:print() -> ')

    lua_testclass.print(self)

end

 

a = derived()

a:print()

 

This gave me an error „lua runtime error” so basically I still have no idea what is wrong with the code. My guess it that it might be caused by the fact that I load scripts via luacode but still if there is a compilation problem it should give me some hint…

 

Thanks


----------------------------------------------------------------------
Program tylko dla graczy komputerowych!
Ogladaj >>> http://link.interia.pl/f207f

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: error/exception hadling in luabind

Daniel Wallin
Domino wrote:
> Hello,
>
> My question is how to handle errors that tells something more than "lua
> runtime error". In my code I need multiple scripts for the single lua state
> that shouldn't know about each other so I'm using lua code to load the
> scripts (the code comes from this list by the way). Below is the example of
> the code that I have problem with:

When you catch "luabind::error", the Lua error message will be at the
top of the stack. So you can do lua_tostring(L, -1) to get the error
message.

HTH,
--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

------------------------------------------------------------------------------
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: error/exception hadling in luabind

Domino-2
Thanks, I thought that luabind takes the error message from the lua stack.

-----Original Message-----
From: Daniel Wallin [mailto:[hidden email]]
Sent: Tuesday, March 10, 2009 11:36 AM
To: [hidden email]
Subject: Re: [luabind] error/exception hadling in luabind

Domino wrote:
> Hello,
>
> My question is how to handle errors that tells something more than "lua
> runtime error". In my code I need multiple scripts for the single lua
state
> that shouldn't know about each other so I'm using lua code to load the
> scripts (the code comes from this list by the way). Below is the example
of
> the code that I have problem with:

When you catch "luabind::error", the Lua error message will be at the
top of the stack. So you can do lua_tostring(L, -1) to get the error
message.

HTH,
--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

----------------------------------------------------------------------------
--
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user



----------------------------------------------------------------------
Program tylko dla graczy komputerowych!
Ogladaj >>> http://link.interia.pl/f207f 


------------------------------------------------------------------------------
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Passing extra parameters to wrapper function

Kristoffer Danielsson
Consider this:
.def("log", WriteLog) // Not sufficient! Need one more parameter...
 
Inside lua:
log('Hello!')
 
Wrapper in C++:
void WriteLog(HWND hWndEdit, const char *text)
{
    SetWindowText(hWndEdit, text); // hWndEdit provided when binding using ".def"?
}
 
Is this possible? Perhaps using raw()?
Thanks!


Krama någon i vinter! Hitta kärleken här! MSN Dejting
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Passing extra parameters to wrapper function

Daniel Wallin
Kristoffer Danielsson wrote:

> Consider this:
>
> .def("log", WriteLog) // Not sufficient! Need one more parameter...
>
> Inside lua:
>
> log('Hello!')
>
> Wrapper in C++:
>
> void WriteLog(HWND hWndEdit, const char *text)
> {
>     SetWindowText(hWndEdit, text); // hWndEdit provided when binding using ".def"?
> }
>
>  
> Is this possible? Perhaps using raw()?

You can use tag_function() to explicitly specify the signature of any
function object, so you can for example do this:

  def(
      "log"
    , tag_function<void(char const*)>(
          boost::bind(WriteLog, edit_hwdn, _1)
      )
  );


--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user