Ejemplo n.º 1
0
      Wt::WWidget * WebApp::createMenuTree() {
        Wt::WIconPair *mapIcon
            = new Wt::WIconPair("icons/yellow-folder-closed.png",
            "icons/yellow-folder-open.png", false);

        Wt::WTreeNode *rootNode = new Wt::WTreeNode("User MainMenu", mapIcon);
        rootNode->setImagePack("icons/");
        rootNode->expand();
        rootNode->setNodeVisible(false);
        rootNode->setLoadPolicy(Wt::WTreeNode::NextLevelLoading);
        createMenuNode("Account", rootNode, &WebApp::accountView, "icons/edit_user.png");
        createMenuNode("Media Data", rootNode, &WebApp::fileView, "icons/media.png");
        createMenuNode("Profiles", rootNode, &WebApp::profileView, "icons/profile.png");
        createMenuNode("Encodings", rootNode, &WebApp::encodingView, "icons/encode.png");
        createMenuNode("Watch Folder", rootNode, &WebApp::watchFolderView, "icons/folder.png");
        createMenuNode("Settings", rootNode, &WebApp::configurationView, "icons/admin.png");
        createMenuNode("Logout", rootNode, &WebApp::logout, "icons/logout.png");
        rootNode->setMargin(5);

        return rootNode;
      }
Ejemplo n.º 2
0
void OutputItem(lua_State* lua, int i, Wt::WTreeNode* parent, stringstream& ss)
{
    switch (lua_type(lua, i)) {
    case LUA_TNUMBER:
        ss <<  lua_tonumber(lua, i);
        parent->addChildNode(new Wt::WTreeNode(ss.str()));
        break;
    case LUA_TSTRING:
        ss << "\"" << lua_tostring(lua, i) << "\"";
        parent->addChildNode(new Wt::WTreeNode(ss.str()));
        break;
    case LUA_TBOOLEAN:
        if (lua_toboolean(lua, i)) {
            ss << "true";
            parent->addChildNode(new Wt::WTreeNode(ss.str()));
        } else {
            ss << "false";
            parent->addChildNode(new Wt::WTreeNode(ss.str()));
        }
        break;
    case LUA_TTABLE:
    {
        ss << "table";
        Wt::WTreeNode* n = new Wt::WTreeNode(ss.str());
        n->setLoadPolicy(Wt::WTreeNode::NextLevelLoading);
        parent->addChildNode(n);
        OutputTable(lua, i, n);
        n->expand();
        break;
    }
    default:
        parent->addChildNode(new Wt::WTreeNode(luaL_typename(lua, i)));
        break;
    }

}
Ejemplo n.º 3
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);
}