2015-03-09

RLV REPL

This script is being filed under "why the heck didn't I think of this before?" as well as "surely someone else has done this, I wonder why I've never seen it before?"

A little earlier today I found myself needing to quickly test a handful of different RLV commands. Now, as I have done over the past 5 years, I could have made a script, ran it, changed it, ran it again, changed it some more, run it again, etc... Really though, that gets rather tedious. And then it hit me! What I really need is a RLV REPL.

What I came up with isn't a REPL in the strictest sense but it more or less does the job. Rez a cube, throw the script inside and then touch it to turn it on (it'll be obvious when it's on and off). In the on state it listens to all local chat by the object owner and, if the text starts with an @, it repeats it via llOwnerSay. Instant quick and dirty RLV command line/REPL thing!

//////////////////////////////////////////////////////////////////////
// RLV REPL
// By Antony Fairport
//
// RLV REPL - Quick and dirty "REPL" for testing RLV commands.
//
// Revision history:
// ------------------------------------------------------------
//
// 2015-03-09
// Initial revision.
//////////////////////////////////////////////////////////////////////
// Default state.
default
{
//////////////////////////////////////////////////////////////////
// State entry.
state_entry()
{
// Start out in the idle state.
state Idle;
}
}
//////////////////////////////////////////////////////////////////////
// Idle state.
state Idle
{
//////////////////////////////////////////////////////////////////
// State entry.
state_entry()
{
// Show that we're idle.
llSetColor( < 1.0, 0.0, 0.0 >, ALL_SIDES );
llSetText( "RLV REPL idle", < 1.0, 0.0, 0.0 >, 1.0 );
}
//////////////////////////////////////////////////////////////////
// Handle a touch event.
touch_end( integer _ )
{
// If it's our owner touching us...
if ( llDetectedKey( 0 ) == llGetOwner() )
{
// ...fire up the REPL.
state REPL;
}
}
}
//////////////////////////////////////////////////////////////////////
// Active REPL state.
state REPL
{
//////////////////////////////////////////////////////////////////
// State entry.
state_entry()
{
// Show that we're working.
llSetColor( < 0.0, 1.0, 0.0 >, ALL_SIDES );
llSetText( "Listening for RLV commands from\n" + llKey2Name( llGetOwner() ), < 0.0, 1.0, 0.0 >, 1.0 );
// Listen to local chat from the owner.
llListen( 0, "", llGetOwner(), "" );
}
//////////////////////////////////////////////////////////////////
// State exit.
state_exit()
{
// Ensure all restictions are cleared.
llOwnerSay( "@clear" );
}
//////////////////////////////////////////////////////////////////
// Handle incoming listen events.
listen( integer channel, string name, key id, string message )
{
// Local chat?
if ( channel == 0 )
{
// Belt and braces. Yes, I know, we filter when we make the
// listen but, hey, it can't hurt to be really sure, right?
if ( id == llGetOwner() )
{
// Looks like an RLV command?
if ( llGetSubString( message, 0, 0 ) == "@" )
{
// Seems so.
llOwnerSay( message );
llOwnerSay( "Executed: " + message );
}
}
}
}
//////////////////////////////////////////////////////////////////
// Handle a touch event.
touch_end( integer _ )
{
// If it's our owner touching us...
if ( llDetectedKey( 0 ) == llGetOwner() )
{
// ...go idle.
state Idle;
}
}
//////////////////////////////////////////////////////////////////
// Handle changes.
changed( integer change )
{
// Owner has changed?
if ( change & CHANGED_OWNER )
{
// They have. Reset all the things.
llResetScript();
}
}
}
view raw RLV REPL.lsl hosted with ❤ by GitHub
This should save me a bit of faffing about the next time I want to test something.

No comments:

Post a Comment