summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author Jeffrey Clark <dude@zaplabs.com>2016-02-14 23:18:14 -0600
committer Jeffrey Clark <dude@zaplabs.com>2016-02-14 23:18:14 -0600
commit56c0fe0249e3d5d2bf0a10914284498e94da2e1f (patch)
treef01eb446ff4ce964cc9ebe4bb56bdd19e4413d23
parent62cded509482704245d6a2fef8f35027df70a9a4 (diff)
extend lua api, cheat (nw)
-rw-r--r--src/emu/luaengine.cpp78
-rw-r--r--src/emu/luaengine.h7
2 files changed, 85 insertions, 0 deletions
diff --git a/src/emu/luaengine.cpp b/src/emu/luaengine.cpp
index 6bbb9c398b3..bf89139f310 100644
--- a/src/emu/luaengine.cpp
+++ b/src/emu/luaengine.cpp
@@ -14,6 +14,7 @@
#include "luabridge/Source/LuaBridge/LuaBridge.h"
#include <signal.h>
#include "emu.h"
+#include "cheat.h"
#include "drivenum.h"
#include "ui/ui.h"
#include "luaengine.h"
@@ -439,6 +440,51 @@ luabridge::LuaRef lua_engine::l_machine_get_devices(const running_machine *r)
}
//-------------------------------------------------
+// machine_cheat_entries - return cheat entries
+// -> manager:machine():cheat().entries[0]
+//-------------------------------------------------
+
+luabridge::LuaRef lua_engine::l_cheat_get_entries(const cheat_manager *c)
+{
+ cheat_manager *cm = const_cast<cheat_manager *>(c);
+ lua_State *L = luaThis->m_lua_state;
+ luabridge::LuaRef entry_table = luabridge::LuaRef::newTable(L);
+
+ int cheatnum = 0;
+ for (cheat_entry *entry = cm->first(); entry != nullptr; entry = entry->next()) {
+ entry_table[cheatnum++] = entry;
+ }
+
+ return entry_table;
+}
+
+//-------------------------------------------------
+// cheat_entry_state - return cheat entry state
+// -> manager:machine():cheat().entries[0]:state()
+//-------------------------------------------------
+
+int lua_engine::lua_cheat_entry::l_get_state(lua_State *L)
+{
+ cheat_entry *ce = luabridge::Stack<cheat_entry *>::get(L, 1);
+
+ switch (ce->state())
+ {
+ case SCRIPT_STATE_ON:
+ lua_pushliteral(L, "on");
+ case SCRIPT_STATE_RUN:
+ lua_pushliteral(L, "run");
+ case SCRIPT_STATE_CHANGE:
+ lua_pushliteral(L, "change");
+ case SCRIPT_STATE_COUNT:
+ lua_pushliteral(L, "count");
+ default:
+ lua_pushliteral(L, "off");
+ }
+
+ return 1;
+}
+
+//-------------------------------------------------
// machine_ioports - return table of ioports
// -> manager:machine():ioport().ports[':P1']
//-------------------------------------------------
@@ -1374,6 +1420,7 @@ void lua_engine::initialize()
.addFunction ("render", &running_machine::render)
.addFunction ("ioport", &running_machine::ioport)
.addFunction ("parameters", &running_machine::parameters)
+ .addFunction ("cheat", &running_machine::cheat)
.addProperty <luabridge::LuaRef, void> ("devices", &lua_engine::l_machine_get_devices)
.addProperty <luabridge::LuaRef, void> ("screens", &lua_engine::l_machine_get_screens)
.addProperty <luabridge::LuaRef, void> ("options", &lua_engine::l_machine_get_options)
@@ -1395,6 +1442,37 @@ void lua_engine::initialize()
.addProperty <luabridge::LuaRef, void> ("spaces", &lua_engine::l_dev_get_memspaces)
.addProperty <luabridge::LuaRef, void> ("state", &lua_engine::l_dev_get_states)
.endClass()
+ .beginClass <cheat_manager> ("cheat")
+ .addProperty <bool, bool> ("enabled", &cheat_manager::enabled, &cheat_manager::set_enable)
+ .addFunction ("reload", &cheat_manager::reload)
+ .addFunction ("save_all", &cheat_manager::save_all)
+ .addProperty <luabridge::LuaRef, void> ("entries", &lua_engine::l_cheat_get_entries)
+ .endClass()
+ .beginClass <lua_cheat_entry> ("lua_cheat_entry")
+ .addCFunction ("state", &lua_cheat_entry::l_get_state)
+ .endClass()
+ .deriveClass <cheat_entry, lua_cheat_entry> ("cheat_entry")
+ .addFunction ("description", &cheat_entry::description)
+ .addFunction ("comment", &cheat_entry::comment)
+ .addFunction ("has_run_script", &cheat_entry::has_run_script)
+ .addFunction ("has_on_script", &cheat_entry::has_on_script)
+ .addFunction ("has_off_script", &cheat_entry::has_off_script)
+ .addFunction ("has_change_script", &cheat_entry::has_change_script)
+ .addFunction ("execute_off_script", &cheat_entry::execute_off_script)
+ .addFunction ("execute_on_script", &cheat_entry::execute_on_script)
+ .addFunction ("execute_run_script", &cheat_entry::execute_run_script)
+ .addFunction ("execute_change_script", &cheat_entry::execute_change_script)
+ .addFunction ("is_text_only", &cheat_entry::is_text_only)
+ .addFunction ("is_oneshot", &cheat_entry::is_oneshot)
+ .addFunction ("is_onoff", &cheat_entry::is_onoff)
+ .addFunction ("is_value_parameter", &cheat_entry::is_value_parameter)
+ .addFunction ("is_itemlist_parameter", &cheat_entry::is_itemlist_parameter)
+ .addFunction ("is_oneshot_parameter", &cheat_entry::is_oneshot_parameter)
+ .addFunction ("activate", &cheat_entry::activate)
+ .addFunction ("select_default_state", &cheat_entry::select_default_state)
+ .addFunction ("select_previous_state", &cheat_entry::select_previous_state)
+ .addFunction ("select_next_state", &cheat_entry::select_next_state)
+ .endClass()
.beginClass <ioport_manager> ("ioport")
.addFunction ("has_configs", &ioport_manager::has_configs)
.addFunction ("has_analog", &ioport_manager::has_analog)
diff --git a/src/emu/luaengine.h b/src/emu/luaengine.h
index f2e9571dbd7..94b90981819 100644
--- a/src/emu/luaengine.h
+++ b/src/emu/luaengine.h
@@ -24,6 +24,8 @@
#undef None
#endif
+class cheat_manager;
+
struct lua_State;
namespace luabridge
{
@@ -149,6 +151,11 @@ private:
int l_end_recording(lua_State *L);
};
+ static luabridge::LuaRef l_cheat_get_entries(const cheat_manager *c);
+ struct lua_cheat_entry {
+ int l_get_state(lua_State *L);
+ };
+
static luabridge::LuaRef l_ui_get_options(const ui_manager *ui);
struct lua_options_entry {
int l_entry_value(lua_State *L);