Luwra C++ wrapper updated

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

Luwra C++ wrapper updated

Ole Krüger
Hello everybody,

quite a while ago I chose to release the header-only C++14 wrapper I have been using. It focuses on minimal overhead, which reflects greatly in terms of performance. 


I have been cleaning up some of the internals aswell as the exposed API to make things a little easier to use. 

I would love to read some feedback.

Ole



Reply | Threaded
Open this post in threaded view
|

Re: Luwra C++ wrapper updated

Nagaev Boris
On Mon, Nov 9, 2015 at 12:04 AM, Ole Krüger <[hidden email]> wrote:

> Hello everybody,
>
> quite a while ago I chose to release the header-only C++14 wrapper I have
> been using. It focuses on minimal overhead, which reflects greatly in terms
> of performance.
>
> On GitHub: https://github.com/vapourismo/luwra
>
> I have been cleaning up some of the internals aswell as the exposed API to
> make things a little easier to use.
>
> I would love to read some feedback.
>
> Ole
>

Hi, Ole

nice work!

1. Please enable Travis CI to run tests automatically.

2. Can you add support of Lua errors vs C++ exceptions conversion?

I use the following wrapper class which converts C++ LuaCfunction
throwing C++ exceptions to LuaCFunction throwing Lua errors:

template<lua_CFunction F>
struct wrap {
    static int func(lua_State* L) {
        try {
            return F(L);
        } catch (std::exception& e) {
            lua_pushstring(L, e.what());
        } catch (...) {
            lua_pushliteral(L, "Unknown exception");
        }
        return lua_error(L);
    }
};

int foo(lua_State* L) {
    throw std::logical_error("I am foo!");
}

luaL_Reg module_functions[] = {
    {"foo", wrap<foo>::func},
    {}
};


--


Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: Luwra C++ wrapper updated

Ole Krüger
Hello,

I'd love to integrate Travis CI, but they sadly do not support C++14 compilers. Some other CI provider might support C++14 - I have yet to come around and test those.

Catching exceptions by default is not something I plan on adding, but some functionality which allows the user to automatically handle exceptions or convert them to Lua errors is a very good idea.

Ole


On Sun, 8 Nov 2015 at 22:29 Nagaev Boris <[hidden email]> wrote:
On Mon, Nov 9, 2015 at 12:04 AM, Ole Krüger <[hidden email]> wrote:
> Hello everybody,
>
> quite a while ago I chose to release the header-only C++14 wrapper I have
> been using. It focuses on minimal overhead, which reflects greatly in terms
> of performance.
>
> On GitHub: https://github.com/vapourismo/luwra
>
> I have been cleaning up some of the internals aswell as the exposed API to
> make things a little easier to use.
>
> I would love to read some feedback.
>
> Ole
>

Hi, Ole

nice work!

1. Please enable Travis CI to run tests automatically.

2. Can you add support of Lua errors vs C++ exceptions conversion?

I use the following wrapper class which converts C++ LuaCfunction
throwing C++ exceptions to LuaCFunction throwing Lua errors:

template<lua_CFunction F>
struct wrap {
    static int func(lua_State* L) {
        try {
            return F(L);
        } catch (std::exception& e) {
            lua_pushstring(L, e.what());
        } catch (...) {
            lua_pushliteral(L, "Unknown exception");
        }
        return lua_error(L);
    }
};

int foo(lua_State* L) {
    throw std::logical_error("I am foo!");
}

luaL_Reg module_functions[] = {
    {"foo", wrap<foo>::func},
    {}
};


--


Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: Luwra C++ wrapper updated

Nagaev Boris
On Mon, Nov 9, 2015 at 12:53 AM, Ole Krüger <[hidden email]> wrote:
> Hello,
>
> I'd love to integrate Travis CI, but they sadly do not support C++14
> compilers. Some other CI provider might support C++14 - I have yet to come
> around and test those.

Travis does support any compiler you can install :)

Some links about this particular case:

https://stackoverflow.com/questions/22111549/travis-ci-with-clang-3-4-and-c11
https://jonasw.de/blog/2015/07/22/develop/cplusplus14-on-travis-with-cmake/

> Catching exceptions by default is not something I plan on adding, but some
> functionality which allows the user to automatically handle exceptions or
> convert them to Lua errors is a very good idea.
>
> Ole
>
>
> On Sun, 8 Nov 2015 at 22:29 Nagaev Boris <[hidden email]> wrote:
>>
>> On Mon, Nov 9, 2015 at 12:04 AM, Ole Krüger <[hidden email]> wrote:
>> > Hello everybody,
>> >
>> > quite a while ago I chose to release the header-only C++14 wrapper I
>> > have
>> > been using. It focuses on minimal overhead, which reflects greatly in
>> > terms
>> > of performance.
>> >
>> > On GitHub: https://github.com/vapourismo/luwra
>> >
>> > I have been cleaning up some of the internals aswell as the exposed API
>> > to
>> > make things a little easier to use.
>> >
>> > I would love to read some feedback.
>> >
>> > Ole
>> >
>>
>> Hi, Ole
>>
>> nice work!
>>
>> 1. Please enable Travis CI to run tests automatically.
>>
>> 2. Can you add support of Lua errors vs C++ exceptions conversion?
>>
>> I use the following wrapper class which converts C++ LuaCfunction
>> throwing C++ exceptions to LuaCFunction throwing Lua errors:
>>
>> template<lua_CFunction F>
>> struct wrap {
>>     static int func(lua_State* L) {
>>         try {
>>             return F(L);
>>         } catch (std::exception& e) {
>>             lua_pushstring(L, e.what());
>>         } catch (...) {
>>             lua_pushliteral(L, "Unknown exception");
>>         }
>>         return lua_error(L);
>>     }
>> };
>>
>> int foo(lua_State* L) {
>>     throw std::logical_error("I am foo!");
>> }
>>
>> luaL_Reg module_functions[] = {
>>     {"foo", wrap<foo>::func},
>>     {}
>> };
>>
>>
>> --
>>
>>
>> Best regards,
>> Boris Nagaev
>>
>



--


Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: Luwra C++ wrapper updated

Ole Krüger
On Sun, 8 Nov 2015 at 23:00 Nagaev Boris <[hidden email]> wrote:
On Mon, Nov 9, 2015 at 12:53 AM, Ole Krüger <[hidden email]> wrote:
> Hello,
>
> I'd love to integrate Travis CI, but they sadly do not support C++14
> compilers. Some other CI provider might support C++14 - I have yet to come
> around and test those.

Travis does support any compiler you can install :)

Some links about this particular case:

https://stackoverflow.com/questions/22111549/travis-ci-with-clang-3-4-and-c11
https://jonasw.de/blog/2015/07/22/develop/cplusplus14-on-travis-with-cmake/

> Catching exceptions by default is not something I plan on adding, but some
> functionality which allows the user to automatically handle exceptions or
> convert them to Lua errors is a very good idea.
>
> Ole
>
>
> On Sun, 8 Nov 2015 at 22:29 Nagaev Boris <[hidden email]> wrote:
>>
>> On Mon, Nov 9, 2015 at 12:04 AM, Ole Krüger <[hidden email]> wrote:
>> > Hello everybody,
>> >
>> > quite a while ago I chose to release the header-only C++14 wrapper I
>> > have
>> > been using. It focuses on minimal overhead, which reflects greatly in
>> > terms
>> > of performance.
>> >
>> > On GitHub: https://github.com/vapourismo/luwra
>> >
>> > I have been cleaning up some of the internals aswell as the exposed API
>> > to
>> > make things a little easier to use.
>> >
>> > I would love to read some feedback.
>> >
>> > Ole
>> >
>>
>> Hi, Ole
>>
>> nice work!
>>
>> 1. Please enable Travis CI to run tests automatically.
>>
>> 2. Can you add support of Lua errors vs C++ exceptions conversion?
>>
>> I use the following wrapper class which converts C++ LuaCfunction
>> throwing C++ exceptions to LuaCFunction throwing Lua errors:
>>
>> template<lua_CFunction F>
>> struct wrap {
>>     static int func(lua_State* L) {
>>         try {
>>             return F(L);
>>         } catch (std::exception& e) {
>>             lua_pushstring(L, e.what());
>>         } catch (...) {
>>             lua_pushliteral(L, "Unknown exception");
>>         }
>>         return lua_error(L);
>>     }
>> };
>>
>> int foo(lua_State* L) {
>>     throw std::logical_error("I am foo!");
>> }
>>
>> luaL_Reg module_functions[] = {
>>     {"foo", wrap<foo>::func},
>>     {}
>> };
>>
>>
>> --
>>
>>
>> Best regards,
>> Boris Nagaev
>>
>



--


Best regards,
Boris Nagaev


Continuous integration is now active. I managed to make Travis compile using Clang 3.7 and GCC 5 against the latest revision of each Lua 5.3, 5.2 and 5.1.

I noticed a bug with LuaJIT where checking user types either goes into an infinite loop or throws an unknown exception - once that is resolved I'll add LuaJIT aswell.

Ole
Reply | Threaded
Open this post in threaded view
|

Re: Luwra C++ wrapper updated

Nagaev Boris
> Continuous integration is now active. I managed to make Travis compile using
> Clang 3.7 and GCC 5 against the latest revision of each Lua 5.3, 5.2 and
> 5.1.

Nice work!

Next step is to measure code coverage :)

> I noticed a bug with LuaJIT where checking user types either goes into an
> infinite loop or throws an unknown exception - once that is resolved I'll
> add LuaJIT aswell.

Which version of LuaJIT have you tried?


--


Best regards,
Boris Nagaev

Reply | Threaded
Open this post in threaded view
|

Re: Luwra C++ wrapper updated

Ole Krüger
On Wed, 11 Nov 2015 at 10:01 Nagaev Boris <[hidden email]> wrote:
Which version of LuaJIT have you tried?

I used 2.0.4. Curiously the exception gets thrown by luaL_checkudata, which in my opionion should not be possible. Maybe it is the testing framework. 

Ole