Create function pointer to lua function adapter and migrate what we can
[lsnes.git] / lua / hostmemory.cpp
blobd814ba0b3ec182192a57f69945d2f8df1b8c6ac7
1 #include "lua-int.hpp"
2 #include "moviedata.hpp"
4 namespace
6 function_ptr_luafun hm_read("hostmemory.read", [](lua_State* LS, const std::string& fname) -> int {
7 size_t address = get_numeric_argument<size_t>(LS, 1, fname.c_str());
8 auto& h = get_host_memory();
9 if(address >= h.size()) {
10 lua_pushboolean(LS, 0);
11 return 1;
13 lua_pushnumber(LS, static_cast<uint8_t>(h[address]));
14 return 1;
15 });
17 function_ptr_luafun hm_write("hostmemory.write", [](lua_State* LS, const std::string& fname) -> int {
18 size_t address = get_numeric_argument<size_t>(LS, 1, fname.c_str());
19 uint8_t value = get_numeric_argument<uint8_t>(LS, 2, fname.c_str());
20 auto& h = get_host_memory();
21 if(address >= h.size())
22 h.resize(address + 1);
23 h[address] = value;
24 return 0;
25 });