Exemplo n.º 1
0
 Wt::WTreeNode * WebApp::createMenuNode(const Wt::WString& label, Wt::WTreeNode *parentNode, ShowExample f, const char * icon) {
   Wt::WIconPair *labelIcon = new Wt::WIconPair(icon, icon, false);
   labelIcon->icon1()->resize(30, 30);
   labelIcon->icon2()->resize(30, 30);
   Wt::WTreeNode *node = new Wt::WTreeNode(label, labelIcon, parentNode);
   node->label()->setFormatting(Wt::WText::PlainFormatting);
   node->label()->clicked.connect(this, f);
   node->labelIcon()->icon1Clicked.connect(this, f);
   node->labelIcon()->icon2Clicked.connect(this, f);
   node->labelIcon()->setStyleClass("licon");
   node->setSelectable(true);
   return node;
 }
Exemplo n.º 2
0
void Tester::Match(lua_sandbox* lsb, const string& input)
{
    lua_State* lua = lsb_get_lua(lsb);
    if (!lua) return;

    if (!CreateGlobalMatch(lua)) {
        stringstream ss;
        ss << "lpeg.match is not available";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    if (lsb_pcall_setup(lsb, kMatchFunction)) {
        stringstream ss;
        ss << "lsb_pcall_setup() failed";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    lua_getglobal(lua, "grammar");
    if (!lua_isuserdata(lua, -1)) {
        stringstream ss;
        ss << "no global grammar variable was found";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        return;
    }

    lua_pushstring(lua, input.c_str());
    if (lua_pcall(lua, 2, LUA_MULTRET, 0) != 0) {
        char err[LSB_ERROR_SIZE];
        int len = snprintf(err, LSB_ERROR_SIZE, "%s() %s", kMatchFunction,
                           lua_tostring(lua, -1));
        if (len >= LSB_ERROR_SIZE || len < 0) {
            err[LSB_ERROR_SIZE - 1] = 0;
        }
        stringstream ss;
        ss << err;
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
        Wt::log("info") << ss.str();
        lsb_terminate(lsb, err);
        return;
    }
    // iterater over the results
    int results = lua_gettop(lua);
    if (LUA_TNIL == lua_type(lua, 1)) {
        stringstream ss;
        ss << "no match";
        Wt::WText* t = new Wt::WText(ss.str(), mResult);
        t->setStyleClass("result_error");
    } else {
        Wt::WTree* tree = new Wt::WTree(mResult);
        tree->setSelectionMode(Wt::SingleSelection);
        Wt::WTreeNode* root = new Wt::WTreeNode("Returned Values");
        root->setStyleClass("tree_results");
        tree->setTreeRoot(root);
        root->label()->setTextFormat(Wt::PlainText);
        root->setLoadPolicy(Wt::WTreeNode::NextLevelLoading);
        for (int i = 1; i <= results; ++i) {
            stringstream ss;
            OutputItem(lua, i, root, ss);
        }
        root->expand();
    }
    lua_pop(lua, lua_gettop(lua)); // clear the stack
    lsb_pcall_teardown(lsb);
}