3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-29 07:19:23 +01:00

Update Plang submodule

This commit is contained in:
Pragmatic Software 2020-09-20 23:19:47 -07:00
parent d2030e21fd
commit 268523d493
2 changed files with 16 additions and 13 deletions

2
Plang

@ -1 +1 @@
Subproject commit c38c089480d7844bddc5769f6e5f539e21b52ba2 Subproject commit ce9e56be7f51ec08d77106036fda273a7ec78f93

View File

@ -1,7 +1,7 @@
# File: Plang.pm # File: Plang.pm
# Author: pragma- # Author: pragma-
# #
# Purpose: Simplified scripting language for creating advanced PBot factoids # Purpose: Scripting language for creating advanced PBot factoids
# and interacting with various internal PBot APIs. # and interacting with various internal PBot APIs.
# This Source Code Form is subject to the terms of the Mozilla Public # This Source Code Form is subject to the terms of the Mozilla Public
@ -27,28 +27,30 @@ sub initialize {
# needing to restart PBot # needing to restart PBot
require "$path/Interpreter.pm"; require "$path/Interpreter.pm";
require "$path/AstInterpreter.pm"; require "$path/AstInterpreter.pm";
require "$path/Grammar.pm"; require "$path/Grammar.pm"; # FIXME: this module cannot be reloaded
require "$path/Parser.pm"; require "$path/Parser.pm";
require "$path/Lexer.pm"; require "$path/Lexer.pm";
require "$path/Types.pm"; require "$path/Types.pm";
require "$path/Validator.pm";
# regset plang.debug 0-10 -- Plugin must be reloaded for this value to take effect. # regset plang.debug <AST,VARS,FUNCS,etc>
my $debug = $self->{pbot}->{registry}->get_value('plang', 'debug') // 0; # Plugin must be reloaded for this value to take effect.
my $debug = $self->{pbot}->{registry}->get_value('plang', 'debug') // '';
# create our Plang interpreter object # create our Plang interpreter object
$self->{plang} = Plang::Interpreter->new(embedded => 1, debug => $debug); $self->{plang} = Plang::Interpreter->new(embedded => 1, debug => $debug);
# register some PBot-specific built-in functions # register some PBot-specific built-in functions
$self->{plang}->add_builtin_function('factset', $self->{plang}->add_builtin_function('factset', # function name
# parameters are [['param1 name', default arg], ['param2 name', default arg], ...] # parameters are [[type, param1 name, default arg], [type, param2 name, default arg], ...]
[ [
[['TYPE', 'String'], 'channel', undef], [['TYPE', 'String'], 'channel', undef], # param 1
[['TYPE', 'String'], 'keyword', undef], [['TYPE', 'String'], 'keyword', undef], # param 2
[['TYPE', 'String'], 'text', undef] [['TYPE', 'String'], 'text', undef], # param 3
], ],
['TYPE', 'String'], # return type ['TYPE', 'String'], # return type
sub { $self->plang_builtin_factset(@_) }, sub { $self->plang_builtin_factset(@_) }, # builtin subref
sub { $self->plang_validate_builtin_factset(@_) } sub { $self->plang_validate_builtin_factset(@_) } # type-checker subref
); );
$self->{plang}->add_builtin_function('factget', $self->{plang}->add_builtin_function('factget',
@ -100,6 +102,7 @@ sub initialize {
$self->{pbot}->{commands}->register(sub { $self->cmd_plangrepl(@_) }, "plangrepl", 0); $self->{pbot}->{commands}->register(sub { $self->cmd_plangrepl(@_) }, "plangrepl", 0);
} }
# runs when plugin is unloaded
sub unload { sub unload {
my $self = shift; my $self = shift;
$self->{pbot}->{commands}->unregister("plang"); $self->{pbot}->{commands}->unregister("plang");