Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006106opensim[REGION] Script Functionspublic2012-07-25 14:172012-10-26 02:07
ReporterSignpostMarv 
Assigned Tojustincc 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Versionmaster (dev code) 
Target VersionFixed in Version 
Summary0006106: ability for listeners to be filtered by regular expression
DescriptionAdded a function that behaves identically to llListen() except for a new parameter which acts as a bitfield to indicate which of the string parameters should be treated as a regular expression.

1 corresponds to the name parameter
2 corresponds to the message parameter

so 3 corresponds to both :D
Steps To Reproducestring input;

output()
{
    llOwnerSay("/me recorded: " + input);
    llOwnerSay("/me receieved: " + (string)((integer)input));
    input = "";
    llSetTimerEvent(0);
}

display()
{
    llSetText(input, ZERO_VECTOR, 1);
}

default
{
    state_entry()
    {
        input = "";
        osListenRegex(0, "", NULL_KEY, "^(\\d|Enter|Backspace|Del)$", 2);
    }

    listen(integer c, string n, key i, string m)
    {
        llOwnerSay("/me heard: " + m);
        if(osRegexIsMatch(m, "^\\d$"))
        {
            input += m;
        }
        else if(m == "Enter")
        {
            output();
            return;
        }
        else if(m == "Backspace" && input != "")
        {
            input = llGetSubString(input, 0, -2);
        }
        else if(m == "Del")
        {
            input = "";
            display();
            llSetTimerEvent(0);
            return;
        }
        display();
        llSetTimerEvent(2);
    }

    timer()
    {
        output();
    }
}
TagsNo tags attached.
Git Revision or version number3cf8edf
Run ModeStandalone (1 Region)
Physics EngineBasicPhysics
Environment.NET / Windows32
Mono VersionNone
Viewer
Attached Filespatch file icon osListenRegex.patch [^] (17,584 bytes) 2012-07-25 14:17 [Show Content]
patch file icon osListenRegex-with-osRegexIsMatch-copypasta.patch [^] (24,025 bytes) 2012-07-26 10:25 [Show Content]
patch file icon osListenRegex-with-constants.patch [^] (34,129 bytes) 2012-07-30 08:16 [Show Content]
patch file icon osListenRegex-rebase.patch [^] (34,013 bytes) 2012-08-01 08:50 [Show Content]
patch file icon osListenRegex-duplicated-constants.patch [^] (37,080 bytes) 2012-08-01 09:41 [Show Content]
patch file icon osListenRegex-rewritten-refactored.patch [^] (28,231 bytes) 2012-10-23 15:09 [Show Content]

- Relationships

-  Notes
(0021897)
dahlia (manager)
2012-07-26 00:25

interesting idea, but I wonder if there is some way this could be done with something more generic, perhaps an osRegex()? that way it could be used in other areas of a script besides listen filtering.
(0021898)
SignpostMarv (reporter)
2012-07-26 09:06

implementing a function that wraps to Regex.IsMatch() is relatively trivial in comparison and for the use-case this was designed for it would be called *after* listen() has fired, whereas osListenRegex() prevents listen() from firing when you know you don't want it to. Currently trying to fix a bug this patch introduces, so if I can't get it fixed I'll get to integer osRegexIsMatch(string input, string pattern) :)
(0021899)
SignpostMarv (reporter)
2012-07-26 10:15
edited on: 2012-07-26 10:26

Changed the example script to what I'm actually using it for. Turns out I needed osRegexIsMatch as well :D

The third patch includes a fix that broke existing script states and fixes copypasta.

It seems we can't delete our own attachments on the mantis :

(0021903)
justincc (administrator)
2012-07-26 23:09
edited on: 2012-07-26 23:10

Without having looked through this super-thoroughly, I think this is a reasonable function - I can imagine it would be good to be able to listen for certain matching messages or things without the overhead of generating listen events. A couple of points

* Please don't use magic numbers. '1' and '2' must have meaningfully named constants that can be used by scripts. The same is true of internal code. Possibly internal code should use bools rather than packing things into a single field, though I know a lot of other code uses such fields. I know some parts of OpenSimulator are using magic numbers but this is a bad thing and should not be perpetuated.

* I don't think it's worth castings ints around to bytes. This just litters the code with casts for very little gain. Please use ints throughout.

(0021904)
SignpostMarv (reporter)
2012-07-26 23:15

* re: magic nubmers: I'm using magic numbers because I'm unsure how to add constants to the script engine.

* re: ints & btes: I started off using bytes throughout and found that didn't work. It's easy enough to change though, so I'll get that done if I have time tomorrow :)
(0021905)
justincc (administrator)
2012-07-26 23:17

* You can see examples of constants accessible by scripts in the ScriptBaseClass. If internal code is to use constants these will have to be duplicated elsewhere. Ultimately this should change but it may be a good thing since internal constants shouldn't really by tied to externally interfaces, though I know OpenSimulator is shot through with this kind of thing.
(0021912)
SignpostMarv (reporter)
2012-07-27 13:46

re: magic numbers & constants, it looks like I'm going to have to add a reference in OpenSim.Region.CoreModules so WorldCommModule can use the constants I've added. Is that going to be an issue ?
(0021925)
justincc (administrator)
2012-07-27 23:28

Well, WorldCommModule is in OpenSim.Region.CoreModules already. We want to avoid other packages referencing OpenSim.Region.CoreModules directly. If you want to share constants (or preferable a flags enum) then the easiest place would be OpenSim.Framework even if that's not very modular.
(0021933)
SignpostMarv (reporter)
2012-07-30 08:16

Forgot to upload the patch last week that had the constants in use.
(0021943)
justincc (administrator)
2012-07-31 23:20

Hi Signpost. Patch does not apply, probably because of the addition of osMin to IOSSLApi, etc. Please could you rebase against current master.

Also, it's hard to tell from the patch but it looks like we're still using magic numbers in WorldCommModule?
(0021944)
SignpostMarv (reporter)
2012-07-31 23:29

The patch was made before the magic numbers discussion (it's why I enquired about adding a reference).

Can constants reference other constants ? A constant needs to be set so they can be used in the LSL script editor...
(0021945)
justincc (administrator)
2012-07-31 23:30

The simplest thing right now would be to dupe the constants in WorldCommModule.
(0021947)
SignpostMarv (reporter)
2012-08-01 08:37

duplicating constants with identical purposes seems almost as bad magic numbers :s

Will get it done :)
(0021950)
SignpostMarv (reporter)
2012-08-01 08:50

rebased patch uploaded :)
(0021952)
SignpostMarv (reporter)
2012-08-01 09:42

Realised I had forgotten to duplicate the constants :P
(0022900)
SignpostMarv (reporter)
2012-10-23 15:09

Made a new patch as the old one wouldn't apply.

New patch also refactors the additional method into a field.
(0022933)
justincc (administrator)
2012-10-26 01:24

Applied as commits 80dcc13a..18b1ee6 on git master. Thanks Marv!
(0022935)
justincc (administrator)
2012-10-26 02:07

Oh yes, could you document these new methods in the OpenSimulator wiki now? Thanks.

- Issue History
Date Modified Username Field Change
2012-07-25 14:17 SignpostMarv New Issue
2012-07-25 14:17 SignpostMarv File Added: osListenRegex.patch
2012-07-25 14:17 SignpostMarv Status new => patch included
2012-07-26 00:25 dahlia Note Added: 0021897
2012-07-26 09:06 SignpostMarv Note Added: 0021898
2012-07-26 10:14 SignpostMarv File Added: osListenRegex-with-osRegexIsMatch.patch
2012-07-26 10:15 SignpostMarv Note Added: 0021899
2012-07-26 10:15 SignpostMarv Steps to Reproduce Updated View Revisions
2012-07-26 10:16 SignpostMarv Note Edited: 0021899 View Revisions
2012-07-26 10:25 SignpostMarv File Added: osListenRegex-with-osRegexIsMatch-copypasta.patch
2012-07-26 10:26 SignpostMarv Note Edited: 0021899 View Revisions
2012-07-26 23:09 justincc Note Added: 0021903
2012-07-26 23:09 justincc Assigned To => justincc
2012-07-26 23:09 justincc Status patch included => patch feedback
2012-07-26 23:10 justincc Note Edited: 0021903 View Revisions
2012-07-26 23:15 SignpostMarv Note Added: 0021904
2012-07-26 23:17 justincc Note Added: 0021905
2012-07-27 13:46 SignpostMarv Note Added: 0021912
2012-07-27 23:28 justincc Note Added: 0021925
2012-07-28 22:29 SignpostMarv File Deleted: osListenRegex-with-osRegexIsMatch.patch
2012-07-30 08:16 SignpostMarv File Added: osListenRegex-with-constants.patch
2012-07-30 08:16 SignpostMarv Note Added: 0021933
2012-07-31 23:20 justincc Note Added: 0021943
2012-07-31 23:29 SignpostMarv Note Added: 0021944
2012-07-31 23:30 justincc Note Added: 0021945
2012-08-01 08:37 SignpostMarv Note Added: 0021947
2012-08-01 08:50 SignpostMarv File Added: osListenRegex-rebase.patch
2012-08-01 08:50 SignpostMarv Note Added: 0021950
2012-08-01 09:41 SignpostMarv File Added: osListenRegex-duplicated-constants.patch
2012-08-01 09:42 SignpostMarv Note Added: 0021952
2012-10-23 15:09 SignpostMarv File Added: osListenRegex-rewritten-refactored.patch
2012-10-23 15:09 SignpostMarv Note Added: 0022900
2012-10-23 15:09 SignpostMarv Status patch feedback => patch included
2012-10-26 01:24 justincc Note Added: 0022933
2012-10-26 01:24 justincc Status patch included => resolved
2012-10-26 01:24 justincc Resolution open => fixed
2012-10-26 02:07 justincc Note Added: 0022935


Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker