Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ -- additional -- ] invoke function #57

Open
DominikMS opened this issue Jun 7, 2014 · 2 comments
Open

[ -- additional -- ] invoke function #57

DominikMS opened this issue Jun 7, 2014 · 2 comments

Comments

@DominikMS
Copy link

Problem:

Double function named invokeFunction

Example:

g_luaState.invokeTabledFunction<int>("tab.func", 5);
g_luaState.invokeTabledFunction<int>("SandBoxed.func", 5);
g_luaState.invokeTabledFunction<int>("func", 5);

Todo:

  • add to: void invokeFunction
  • add to: void setGlobal
  • add to: Type_ getGlobal

Code:

        template<typename Ret_, typename... Args_>
        Ret_ invokeFunction(const std::string &name, Args_&&... args)
        {
            const unsigned int Arg_Count_ = sizeof...(Args_);

            // explode
            std::vector<std::string> explode;
            std::size_t lastpos = 0, pos = name.find(".");

            if(pos == std::string::npos)
                explode.push_back(name);

            while(pos != std::string::npos)
            {
                explode.push_back(std::string(name, lastpos, pos - lastpos).c_str());

                lastpos = ++pos;
                if((pos = name.find(".", pos)) == std::string::npos)
                    explode.push_back(std::string(name, lastpos, pos - lastpos).c_str());
            }

            // find func
            lua_getglobal(state_, explode[0].c_str());
            if(explode.size() > 1)
            {
                for(auto it = explode.begin() + 1; it != explode.end(); it++)
                {
                    lua_getfield(state_, -1, (*it).c_str());
                    if(lua_isnil(state_, -1)) // table not found
                        return Ret_();
                }
            }


            applyTupleLuaFunc(this, state_, std::forward<Args_>(args)...);
            lua_pcall(state_, Arg_Count_, 1, 0);
            return stack<Ret_>::get(this, state_, -1);
        }
@Tomasu Tomasu closed this as completed in ff6b21a Jun 7, 2014
@Tomasu
Copy link
Owner

Tomasu commented Jun 7, 2014

Ah crud. I didn't think about that. Yeah, the namespace stuff isn't in yet, so I can just remove the one with a namespace.

@DominikMS DominikMS changed the title invokeFunction bug invokeFunction [bug] / [feature] Jun 8, 2014
@Tomasu
Copy link
Owner

Tomasu commented Jun 8, 2014

I think something like that would work well with future support for namespaces in Class<>(). For instance: glue.Class<Some::NameSpace::Foo>("Some.Namespace.Foo").

@Tomasu Tomasu reopened this Jun 8, 2014
@DominikMS DominikMS changed the title invokeFunction [bug] / [feature] [ -- additional -- ] invoke function Jun 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants