Previous Thread
Next Thread
Print Thread
Page 13 of 13 1 2 11 12 13
#111323 - 11/22/17 03:22 PM Re: 8bit Apples - Apple I, II, /// and the 16 bit GS [Re: crazyc]  
Joined: Feb 2014
Posts: 104
Golden Child Offline
Senior Member
Golden Child  Offline
Senior Member

Joined: Feb 2014
Posts: 104
Originally Posted by crazyc
There shouldn't be any issues enabling that.


Cool. That was one of the things that would crash when I'd experiment.

Now I just have to remember not to try to copy with CTRL+C in the mame console. kaboom! Old habits die hard.


Interestingly, if I type CTRL+V (for paste) I see a ^V in the console, but it takes two deletes to remove it.

If I only delete once after hitting CTRL+V I get this "unexpected symbol" and I could not figure out why my command didn't work.

type print("hello") then CTRL+V and then delete once, the command line looks ok, but there's a bizarro character at the end.

This is with Ubuntu terminal console.

Code
print("hello")
error: 	[string "print("hello")"]:1: unexpected symbol near '<\127>'




I can edit the plugins/console/init.lua and add this line:

Code
local ln = require("linenoise")
ln_global = ln


so I can access the linenoise as the global variable ln_global and then I can save the history as:

Code
ln_global.savehistory("mysavehistoryln.txt")


and loading that into a text editor I can see that there's a strange 007F character at the end.


Is there an easy way of accessing the actual linenoise history entries, like a "history" command in bash, for example?

If I type ln_global. and then hit TAB to complete I get:

Code
ln_global.                                  

addcompletion
clearscreen
sethistorymaxlen
linenoise
lines
historysave
line
preload
loadhistory
savehistory
setcompletion
addhistory
refresh
historyadd
historysetmaxlen
historyload



But none of those seem to give me access to the actual history.


edit:
Hmmm, why not savehistory to /dev/stdout, that seems to work.

Code
ln_global.savehistory("/dev/stdout")


Last edited by Golden Child; 11/22/17 03:55 PM.
#111324 - 11/22/17 03:56 PM Re: 8bit Apples - Apple I, II, /// and the 16 bit GS [Re: rfka01]  
Joined: Jan 2012
Posts: 692
crazyc Offline
Senior Member
crazyc  Offline
Senior Member

Joined: Jan 2012
Posts: 692
The linenoise function char **linenoiseHistory(int *len) provides access to the history but it's not passed to lua in to lua-linenoise. If you can add it that'd be great, it shouldn't be hard to do.

#111325 - 11/22/17 04:12 PM Re: 8bit Apples - Apple I, II, /// and the 16 bit GS [Re: crazyc]  
Joined: Feb 2014
Posts: 104
Golden Child Offline
Senior Member
Golden Child  Offline
Senior Member

Joined: Feb 2014
Posts: 104
Originally Posted by crazyc
The linenoise function char **linenoiseHistory(int *len) provides access to the history but it's not passed to lua in to lua-linenoise. If you can add it that'd be great, it shouldn't be hard to do.


sounds like an interesting idea, I'll give it a shot.

#111329 - 11/22/17 10:41 PM Re: 8bit Apples - Apple I, II, /// and the 16 bit GS [Re: Golden Child]  
Joined: Feb 2014
Posts: 104
Golden Child Offline
Senior Member
Golden Child  Offline
Senior Member

Joined: Feb 2014
Posts: 104

I took a stab at adding it to linenoise.c, this seems to work. Cool!

Code
static int l_gethistorytable(lua_State *L)
{
    int i,j;
    char ** phist;
    int lenhist = linenoiseHistoryGetMaxLen();

    phist = linenoiseHistory(&lenhist); 

    lua_newtable(L);
    i = 1;

    for (j=0; j<lenhist; j++){

        /* create result table */
        lua_pushnumber(L, i++);  /* push key */
        lua_pushstring(L, (char *)*(phist+j));  /* push value */
        lua_settable(L, -3);  /* adds key and value to table on top of stack */
      }
      return 1;  /* table is already on top */
}

luaL_Reg linenoise_funcs[] = {
    { "linenoise", l_linenoise },
    { "historyadd", l_historyadd },
    { "historysetmaxlen", l_historysetmaxlen },
    { "historysave", l_historysave },
    { "historyload", l_historyload },
    { "clearscreen", l_clearscreen },
    { "setcompletion", l_setcompletion},
    { "addcompletion", l_addcompletion },
    { "preload", l_preloadbuffer },
    { "refresh", l_refresh },

    /* Aliases for more consistent function names */
    { "addhistory", l_historyadd },
    { "sethistorymaxlen", l_historysetmaxlen },
    { "savehistory", l_historysave },
    { "loadhistory", l_historyload },

    { "line", l_linenoise },
    { "lines", l_lines },

    { "gethistory", l_gethistorytable},  // added function to gethistory
    { NULL, NULL }
};



I think you don't see the current command in the history list because it gets added after it gets executed.

Code
MAME debugger version 0.191 (mame0191-183-g346a935839-dirty)
Currently targeting a2600 (Atari 2600 (NTSC))
[MAME]> print(#ln_global.gethistory())
0
[MAME]> print(#ln_global.gethistory())
1
[MAME]> function printt(a) local i,j; for i,j in pairs(a) do print(i,j) end end

[MAME]> printt(ln_global.gethistory())
1	print(#ln_global.gethistory())
2	function printt(a) local i,j; for i,j in pairs(a) do print(i,j) end end

[MAME]> printt(ln_global.gethistory())
1	print(#ln_global.gethistory())
2	function printt(a) local i,j; for i,j in pairs(a) do print(i,j) end end
3	printt(ln_global.gethistory())
[MAME]> 

#111330 - 11/23/17 05:23 AM Re: 8bit Apples - Apple I, II, /// and the 16 bit GS [Re: Golden Child]  
Joined: Feb 2004
Posts: 1,866
Vas Crabb Offline
Very Senior Member
Vas Crabb  Offline
Very Senior Member

Joined: Feb 2004
Posts: 1,866
Sydney, Australia
Originally Posted by Golden Child
Interestingly, if I type CTRL+V (for paste) I see a ^V in the console, but it takes two deletes to remove it.

If I only delete once after hitting CTRL+V I get this "unexpected symbol" and I could not figure out why my command didn't work.

type print("hello") then CTRL+V and then delete once, the command line looks ok, but there's a bizarro character at the end.

This is with Ubuntu terminal console.

Code
print("hello")
error: 	[string "print("hello")"]:1: unexpected symbol near '<\127>'



Ctrl-V means "interpret the next character literally", so Ctrl-V Ctrl-C will type a literal ETX character rather than sending SIGINT, Ctrl-V Delete will type a literal DEL rather than deleting the previous character, etc.

#111333 - 11/23/17 08:21 AM Re: 8bit Apples - Apple I, II, /// and the 16 bit GS [Re: Vas Crabb]  
Joined: Feb 2014
Posts: 104
Golden Child Offline
Senior Member
Golden Child  Offline
Senior Member

Joined: Feb 2014
Posts: 104
Originally Posted by Vas Crabb

Ctrl-V means "interpret the next character literally", so Ctrl-V Ctrl-C will type a literal ETX character rather than sending SIGINT, Ctrl-V Delete will type a literal DEL rather than deleting the previous character, etc.


Ohhhh, now that makes perfect sense. That explains why if I'd type Ctrl+v Return that I'd get a ^M or Ctrl+v left arrow I'd get ESC [ D. So that's why I'd get an 007F character from Ctrl+V DEL.

I guess that's a keystroke from VIM.

And sure enough, the code in 3rdparty/linenoise/linenoise.c is pretty straightforward.

Code
    case ctrl('V'):    /* ctrl-v */
            if (has_room(current, 3)) {
                /* Insert the ^V first */
                if (insert_char(current, current->pos, c)) {
                    refreshLine(current->prompt, current);
                    /* Now wait for the next char. Can insert anything except \0 */
                    c = fd_read(current);

                    /* Remove the ^V first */
                    remove_char(current, current->pos - 1);
                    if (c != -1) {
                        /* Insert the actual char */
                        insert_char(current, current->pos, c);
                    }
                    refreshLine(current->prompt, current);
                }
            }

Last edited by Golden Child; 11/23/17 08:33 AM.
#111335 - 11/23/17 09:29 AM Re: 8bit Apples - Apple I, II, /// and the 16 bit GS [Re: Golden Child]  
Joined: Feb 2014
Posts: 104
Golden Child Offline
Senior Member
Golden Child  Offline
Senior Member

Joined: Feb 2014
Posts: 104
So while we're at it, why not do a historygetmaxlen too:

Code
static int l_gethistorytable(lua_State *L)
{
    int i,j;
    char ** phist;
    int lenhist = linenoiseHistoryGetMaxLen();

    phist = linenoiseHistory(&lenhist); 

    lua_newtable(L); /* put a table on the stack */
    i = 1;

    for (j=0; j<lenhist; j++){
        /* create result table */
        lua_pushnumber(L, i++);  /* push key */
        lua_pushstring(L, phist[j]);  /* push value */
        lua_settable(L, -3);  /* adds key and value to table at position 3 from top of stack */
      }
      return 1;  /* table is already on top */
}


static int l_historygetmaxlen(lua_State *L)
{
      lua_pushinteger(L, linenoiseHistoryGetMaxLen());  /* push max len on stack */
      return 1;  /* number of items on stack */
}

luaL_Reg linenoise_funcs[] = {
    { "linenoise", l_linenoise },
    { "historyadd", l_historyadd },
    { "historysetmaxlen", l_historysetmaxlen },
    { "historysave", l_historysave },
    { "historyload", l_historyload },
    { "clearscreen", l_clearscreen },
    { "setcompletion", l_setcompletion},
    { "addcompletion", l_addcompletion },
    { "preload", l_preloadbuffer },
    { "refresh", l_refresh },

    /* Aliases for more consistent function names */
    { "addhistory", l_historyadd },
    { "sethistorymaxlen", l_historysetmaxlen },
    { "savehistory", l_historysave },
    { "loadhistory", l_historyload },

    { "line", l_linenoise },
    { "lines", l_lines },

    { "gethistory", l_gethistorytable},
    { "historygetmaxlen", l_historygetmaxlen},
    { NULL, NULL }
};




Code
MAME debugger version 0.191 (mame0191-183-g346a935839-dirty)
Currently targeting a2600 (Atari 2600 (NTSC))
[MAME]> print(ln_global.historygetmaxlen())
100
[MAME]> print(ln_global.historysetmaxlen(250))
true
[MAME]> print(ln_global.historygetmaxlen())
250
[MAME]> function printt(a) local i,j; for i,j in pairs(a) do print(i,j) end end
[MAME]> printt(ln_global.gethistory())
1	print(ln_global.historygetmaxlen())
2	print(ln_global.historysetmaxlen(250))
3	print(ln_global.historygetmaxlen())
4	function printt(a) local i,j; for i,j in pairs(a) do print(i,j) end end
[MAME]> 

Page 13 of 13 1 2 11 12 13

Who's Online Now
2 registered members (reenigne, shattered), 21 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Shout Box
Forum Statistics
Forums9
Topics8,439
Posts109,445
Members4,766
Most Online225
May 26th, 2014
Powered by UBB.threads™ PHP Forum Software 7.6.0
Page Time: 0.028s Queries: 16 (0.010s) Memory: 5.0019 MB (Peak: 5.2035 MB) Zlib enabled. Server Time: 2017-11-24 07:15:04 UTC