Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void doFunction(lua_State *L, int argc, t_atom *argv)
- {
- lua_getglobal(L, "require");
- lua_pushstring(L, "foo"); //require("foo")
- if (lua_pcall(L, 1, LUA_MULTRET, 0))
- {
- error("error: %s", lua_tostring(L, -1));
- lua_pop(L, 1);
- return;
- }
- int top = lua_gettop(L);
- lua_getfield(L, -1, "test"); //find foo.test() function
- if (lua_type(L, -1) != LUA_TFUNCTION)
- {
- lua_pop(L, 2);
- return;
- }
- lua_newtable(L);
- for (int i = 0; i < argc; ++i) //convert array to lua table
- {
- lua_pushinteger(L, static_cast<lua_Integer>(i + 1));
- if (argv[i].a_type == A_FLOAT)
- lua_pushnumber(L, static_cast<lua_Number>(argv[i].a_w.w_float));
- else if (argv[i].a_type == A_SYMBOL)
- lua_pushstring(L, argv[i].a_w.w_symbol->s_name);
- lua_settable(L, -3);
- }
- if (lua_pcall(L, 1, LUA_MULTRET, 0)) //call foo.test() function
- {
- error("error: %s", lua_tostring(L, -1));
- lua_pop(L, 1);
- return;
- }
- if (lua_gettop(L) - top)
- {
- //do something with the returned value
- }
- lua_pop(L, 1);
- }
- lua_Debug ar;
- lua_getinfo(L, ">u", &ar);
- printf("%dn", ar.nparams);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement