34 lines
1.8 KiB
PHP
34 lines
1.8 KiB
PHP
<?php
|
|
|
|
require_once "LogicFunction.php";
|
|
|
|
class LuaUtils
|
|
{
|
|
public static function l2pA(array $la): array {
|
|
$r = [];
|
|
$i = 0;
|
|
foreach ($la as $v) {
|
|
$r[$i++] = $v;
|
|
}
|
|
return $r;
|
|
}
|
|
|
|
public static function registerLuaLibs(LuaSandbox &$sandbox): void {
|
|
self::registerLogicUtils($sandbox);
|
|
}
|
|
|
|
public static function registerLogicUtils(LuaSandbox &$sandbox): void {
|
|
$sandbox->registerLibrary("logic", [
|
|
"extend" => fn() => [ call_user_func(array(LogicUtils::class, "extend"), ...func_get_args()) ],
|
|
"complement" => fn() => [ call_user_func(array(LogicUtils::class, "complement"), ...func_get_args()) ],
|
|
"changeRepresentation" => fn() => [ call_user_func(array(LogicUtils::class, "changeRepresentation"), ...func_get_args()) ],
|
|
"genRandomLogicFunction" => fn($iv, $mind, $maxd) => [ call_user_func(array(LogicFunction::class, "genRandom"), self::l2pA($iv), $mind, $maxd)->getExpression() ],
|
|
"genRandomLogicFunctionDNF" => fn($iv) => [ call_user_func(array(LogicFunction::class, "genRandomDNF"), self::l2pA($iv))->getExpression() ],
|
|
"isLogicFunctionValid" => fn($expr) => [ (new LogicFunction($expr))->isValid() ],
|
|
"isLogicFunctionADNF" => fn($iv, $expr) => [ call_user_func(array(LogicFunction::class, "isCorrectDNF"), self::l2pA($iv), $expr) ],
|
|
"collectVariablesFromLogicFunction" => fn($expr) => call_user_func(array(LogicFunction::class, "collectVariables"), $expr),
|
|
"convertLogicFunctionToTruthTable" => fn($expr, $iv) => [ (new LogicFunction($expr, self::l2pA($iv)))->getTruthTable() ],
|
|
"drawLogicFunction" => fn($expr, $iv, $ov) => [ (new LogicFunction($expr, self::l2pA($iv)))->drawNetwork($ov) ],
|
|
]);
|
|
}
|
|
} |