]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script.cpp
Add missing files for a previous commit
[dragonfireclient.git] / src / script.cpp
index edfc596b8f4a114f045c32565d323695fa9359c5..16d8030d6eef7f712e3b7ccfb0e2df5e9d17300a 100644 (file)
@@ -41,74 +41,15 @@ void script_error(lua_State *L, const char *fmt, ...)
        exit(EXIT_FAILURE);
 }
 
-void script_call_va(lua_State *L, const char *func, const char *sig, ...)
-{
-       va_list vl;
-       int narg, nres; /* number of arguments and results */
-
-       va_start(vl, sig);
-       lua_getglobal(L, func); /* push function */
-
-       for (narg = 0; *sig; narg++) {
-               /* repeat for each argument */
-               /* check stack space */
-               luaL_checkstack(L, 1, "too many arguments");
-               switch (*sig++) {
-               case 'd': /* double argument */
-                       lua_pushnumber(L, va_arg(vl, double));
-                       break;
-               case 'i': /* int argument */
-                       lua_pushinteger(L, va_arg(vl, int));
-                       break;
-               case 's': /* string argument */
-                       lua_pushstring(L, va_arg(vl, char *));
-                       break;
-               case '>': /* end of arguments */
-                       goto endargs;
-               default:
-                       script_error(L, "invalid option (%c)", *(sig - 1));
-               }
-       }
-endargs:
-
-       nres = strlen(sig); /* number of expected results */
-
-       if (lua_pcall(L, narg, nres, 0) != 0) /* do the call */
-               script_error(L, "error calling '%s': %s", func, lua_tostring(L, -1));
-       
-       nres = -nres; /* stack index of first result */
-       while (*sig) { /* repeat for each result */
-               switch (*sig++) {
-               case 'd': /* double result */
-                       if (!lua_isnumber(L, nres))
-                       script_error(L, "wrong result type");
-                       *va_arg(vl, double *) = lua_tonumber(L, nres);
-                       break;
-               case 'i': /* int result */
-                       if (!lua_isnumber(L, nres))
-                       script_error(L, "wrong result type");
-                       *va_arg(vl, int *) = lua_tointeger(L, nres);
-                       break;
-               case 's': /* string result */
-                       if (!lua_isstring(L, nres))
-                       script_error(L, "wrong result type");
-                       *va_arg(vl, const char **) = lua_tostring(L, nres);
-                       break;
-               default:
-                       script_error(L, "invalid option (%c)", *(sig - 1));
-               }
-               nres++;
-       }
-
-       va_end(vl);
-}
-
 bool script_load(lua_State *L, const char *path)
 {
        infostream<<"Loading and running script from "<<path<<std::endl;
        int ret = luaL_loadfile(L, path) || lua_pcall(L, 0, 0, 0);
        if(ret){
-               errorstream<<"Failed to load and run script from "<<path<<": "<<lua_tostring(L, -1)<<std::endl;
+               errorstream<<"Failed to load and run script from "<<path<<":"<<std::endl;
+               errorstream<<"[LUA] "<<std::endl;
+               errorstream<<"[LUA] "<<lua_tostring(L, -1)<<std::endl;
+               errorstream<<"[LUA] "<<std::endl;
                lua_pop(L, 1); // Pop error message from stack
                return false;
        }
@@ -122,7 +63,7 @@ lua_State* script_init()
        return L;
 }
 
-lua_State* script_deinit(lua_State *L)
+void script_deinit(lua_State *L)
 {
        lua_close(L);
 }