1 #include "core/command.hpp"
2 #include "core/emucore.hpp"
3 #include "lua/internal.hpp"
4 #include "core/framerate.hpp"
5 #include "core/window.hpp"
9 function_ptr_luafun
lua_print(LS
, "print", [](lua_state
& L
, const std::string
& fname
) -> int {
11 while(!L
.isnone(stacksize
+ 1))
15 for(int i
= 0; i
< stacksize
; i
++) {
17 const char* tmp
= NULL
;
21 } else if(L
.isboolean(i
+ 1) && L
.toboolean(i
+ 1)) {
24 } else if(L
.isboolean(i
+ 1) && !L
.toboolean(i
+ 1)) {
28 tmp
= L
.tolstring(i
+ 1, &len
);
30 tmp
= "(unprintable)";
34 std::string
localmsg(tmp
, tmp
+ len
);
38 toprint
= toprint
+ "\t" + localmsg
;
41 platform::message(toprint
);
45 function_ptr_luafun
lua_exec(LS
, "exec", [](lua_state
& L
, const std::string
& fname
) -> int {
46 std::string text
= L
.get_string(1, fname
.c_str());
47 lsnes_cmd
.invoke(text
);
51 function_ptr_luafun
lua_booted(LS
, "emulator_ready", [](lua_state
& L
, const std::string
& fname
) -> int {
52 L
.pushboolean(lua_booted_flag
? 1 : 0);
56 function_ptr_luafun
lua_utime(LS
, "utime", [](lua_state
& L
, const std::string
& fname
) -> int {
57 uint64_t t
= get_utime();
58 L
.pushnumber(t
/ 1000000);
59 L
.pushnumber(t
% 1000000);
63 function_ptr_luafun
lua_idle_time(LS
, "set_idle_timeout", [](lua_state
& L
, const std::string
& fname
) -> int {
64 lua_idle_hook_time
= get_utime() + L
.get_numeric_argument
<uint64_t>(1, fname
.c_str());
68 function_ptr_luafun
lua_timer_time(LS
, "set_timer_timeout", [](lua_state
& L
, const std::string
& fname
) ->
70 lua_timer_hook_time
= get_utime() + L
.get_numeric_argument
<uint64_t>(1, fname
.c_str());
74 function_ptr_luafun
lua_busaddr(LS
, "bus_address", [](lua_state
& L
, const std::string
& fname
) -> int {
75 uint64_t addr
= L
.get_numeric_argument
<uint64_t>(1, fname
.c_str());
76 auto busrange
= core_get_bus_map();
77 if(!busrange
.second
) {
78 L
.pushstring("This platform does not have bus mapping");
82 L
.pushnumber(busrange
.first
+ (addr
% busrange
.second
));