diff options
| author | 2016-11-15 22:21:07 -0600 | |
|---|---|---|
| committer | 2016-11-15 22:21:07 -0600 | |
| commit | a68d4239929802bca7131d4b97c2b8d149fbbcb9 (patch) | |
| tree | 03a497191ccd83206e94c60aca635eb44d51c0f7 /src | |
| parent | 4d533249fdf28d3a473426130a82e673b1b1d5ec (diff) | |
luaengine: use initializers (nw)
Diffstat (limited to 'src')
| -rw-r--r-- | src/frontend/mame/luaengine.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/frontend/mame/luaengine.cpp b/src/frontend/mame/luaengine.cpp index a69c8a0b8ed..71d937dff95 100644 --- a/src/frontend/mame/luaengine.cpp +++ b/src/frontend/mame/luaengine.cpp @@ -769,18 +769,6 @@ void lua_engine::initialize() return sol::make_object(sol(), sol::nil); return sol::make_object(sol(), driver_list::driver(i)); }; - // this throws an error when implemented as an initializer - emu["item"] = [this](int index) { - save_item *item = new save_item; - if(!machine().save().indexed_item(index, item->base, item->size, item->count)) - { - item->base = nullptr; - item->size = 0; - item->count= 0; - } - return item; - }; - emu["thread"] = []() { context *ctx = new context; ctx->busy = false; ctx->yield = false; return ctx; }; emu.new_usertype<emu_file>("file", sol::call_constructor, sol::constructors<sol::types<const char *, uint32_t>>(), "read", [](emu_file &file, sol::buffer *buff) { buff->set_len(file.read(buff->get_ptr(), buff->get_len())); return buff; }, @@ -799,8 +787,10 @@ void lua_engine::initialize() * thread.yield - check if thread is yielded */ - sol().registry().new_usertype<context>("thread", - sol::meta_function::garbage_collect, sol::destructor([](context *ctx) { delete ctx; }), + emu.new_usertype<context>("thread", sol::call_constructor, sol::initializers([](context &ctx) { + ctx.busy = false; + ctx.yield = false; + }), "start", [this](context &ctx, const char *scr) { std::string script(scr); if(ctx.busy) @@ -854,8 +844,14 @@ void lua_engine::initialize() "busy", sol::readonly(&context::busy), "yield", sol::readonly(&context::yield)); - sol().registry().new_usertype<save_item>("item", - sol::meta_function::garbage_collect, sol::destructor([](save_item *item) { delete item; }), + emu.new_usertype<save_item>("item", sol::call_constructor, sol::initializers([this](save_item &item, int index) { + if(!machine().save().indexed_item(index, item.base, item.size, item.count)) + { + item.base = nullptr; + item.size = 0; + item.count= 0; + } + }), "size", sol::readonly(&save_item::size), "count", sol::readonly(&save_item::count), "read", [this](save_item &item, int offset) -> sol::object { |
