TheLinx / lao

A library for audio output through Lua.
http://thelinx.github.com/lao/
18 stars 2 forks source link

shutdown ao on library removal #8

Open daurnimator opened 7 years ago

daurnimator commented 7 years ago

There was previously ineffective code (removed in a5a9b7b3c2752399877cdfc002cca195d7cc083b) trying to automatically call ao_shutdown if lao was unloaded.

This could be done by e.g. making this userdata an upvalue for all functions

    /* Create object with __gc metamethod so that ao gets shut down on exit */
    lua_newuserdata(L, 0);
    lua_createtable(L, 0, 1);
    lua_pushcfunction(L, l_shutdown);
    lua_setfield(L, -2, "__gc");
    lua_setmetatable(L, -2);