주의 : 아래 글은 전적으로 개인적인 짦은 지식과 소견으로 작성한 글입니다. 제 전공은 경제학이나 국제금융도 아니고 외환이나 주식관련 애널리스트도 아니기에 아래 정보를 활용해서 발생하는 손실이나 손해에 대해서는 아무런 책임을 질 수 없음을 밝힙니다. 그리고 여기에 쓰는 글은 여기저기 널려있는 수많은 정보들을 제 맘대로 발췌해서 만든 내용이 대다수입니다. 이 정보를 자신을 위해 사용할때는 본인 스스로가 결정하시고, 이 글은 그냥 편하게 읽어주시기 바랍니다.
참고로, 저는 무정부주의자도 아니고, 누구를 모함하거나 잘못된 정보를 전달하기 위해 글을 작성하는 사람도 아닙니다. 정부의 정책을 반대하는 것도 아니고, 동조하지도 않습니다. 그냥 개인적인 의견이므로 아래의 글을 읽기가 걱정되신다면 그대로 페이지를 닫아주시기 바랍니다.


블로그에 글을 작성할때 반드시 밝혀야 하는 사항



출처 : http://www.lua.org/pil/25.3.html

As a more advanced example, we will build a wrapper for calling Lua functions, using the vararg facility in C. Our wrapper function (let us call it call_va) receives the name of the function to be called, a string describing the types of the arguments and results, then the list of arguments, and finally a list of pointers to variables to store the results; it handles all the details of the API. With this function, we could write our previous example simply as

    call_va("f", "dd>d", x, y, &z);

where the string "dd>d" means "two arguments of type double, one result of type double". This descriptor can use the letters `d´ for double, `i´ for integer, and `s´ for strings; a `>´ separates arguments from the results. If the function has no results, the `>´ is optional.

   #include <stdarg.h>
    
    void call_va (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);  /* get function */
    
      /* push arguments */
      narg = 0;
      while (*sig) {  /* push arguments */
        switch (*sig++) {
    
          case 'd':  /* double argument */
            lua_pushnumber(L, va_arg(vl, double));
            break;
    
          case 'i':  /* int argument */
            lua_pushnumber(L, va_arg(vl, int));
            break;
    
          case 's':  /* string argument */
            lua_pushstring(L, va_arg(vl, char *));
            break;
    
          case '>':
            goto endwhile;
    
          default:
            error(L, "invalid option (%c)", *(sig - 1));
        }
        narg++;
        luaL_checkstack(L, 1, "too many arguments");
      } endwhile:
    
      /* do the call */
      nres = strlen(sig);  /* number of expected results */
      if (lua_pcall(L, narg, nres, 0) != 0)  /* do the call */
        error(L, "error running function `%s': %s",
                 func, lua_tostring(L, -1));
    
      /* retrieve results */
      nres = -nres;  /* stack index of first result */
      while (*sig) {  /* get results */
        switch (*sig++) {
    
          case 'd':  /* double result */
            if (!lua_isnumber(L, nres))
              error(L, "wrong result type");
            *va_arg(vl, double *) = lua_tonumber(L, nres);
            break;
    
          case 'i':  /* int result */
            if (!lua_isnumber(L, nres))
              error(L, "wrong result type");
            *va_arg(vl, int *) = (int)lua_tonumber(L, nres);
            break;
    
          case 's':  /* string result */
            if (!lua_isstring(L, nres))
              error(L, "wrong result type");
            *va_arg(vl, const char **) = lua_tostring(L, nres);
            break;
    
          default:
            error(L, "invalid option (%c)", *(sig - 1));
        }
        nres++;
      }
      va_end(vl);
    }






포스팅이 유익 하셨다면 RSS 구독을 신청하세요

Trackback Address >> http://dolba.net/tt/k2club/trackback/2404