• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ dostring函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中dostring函数的典型用法代码示例。如果您正苦于以下问题:C++ dostring函数的具体用法?C++ dostring怎么用?C++ dostring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了dostring函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: include_path

	inline void include_path(lua_State *L,const char * path)
	{
		std::ostringstream stream;

		stream << "package.path = package.path .. \";" << path << "/?.lua\"";

		dostring(L,stream.str().c_str());
	}
开发者ID:xubingyue,项目名称:mini-lake,代码行数:8,代码来源:luapi.hpp


示例2: handle_luainit

static int handle_luainit (lua_State *L) {
  const char *init = getenv("LUA_INIT");
  if (init == NULL) return 0;  /* status OK */
  else if (init[0] == '@')
    return dofile(L, init+1);
  else
    return dostring(L, init, "=LUA_INIT");
}
开发者ID:ggreco,项目名称:lpcgame,代码行数:8,代码来源:lua.c


示例3: main

int main(int argc,char* argv[]) {
  lua_State *L;
  int ok;
  printf("[C] Welcome to the simple embedded lua example\n");
  printf("[C] We are in C\n");
  printf("[C] opening a lua state & loading the libraries\n");
  L=lua_open();
  luaopen_base(L);
  luaopen_string(L);
  luaopen_math(L);
  printf("[C] now loading the SWIG wrapped library\n");
  luaopen_example(L);
  printf("[C] all looks ok\n");
  printf("\n");
  if (argc != 2 || argv[1] == NULL || strlen(argv[1]) == 0) {
    printf("[C] ERROR: no lua file given on command line\n");
    exit(3);
  }
  printf("[C] let's load the file '%s'\n", argv[1]);
  printf("[C] any lua code in this file will be executed\n");
  if (luaL_loadfile(L, argv[1]) || lua_pcall(L, 0, 0, 0)) {
    printf("[C] ERROR: cannot run lua file: %s",lua_tostring(L, -1));
    exit(3);
  }
  printf("[C] We are now back in C, all looks ok\n");
  printf("\n");
  printf("[C] let's call the function 'do_tests()'\n");
  ok=dostring(L,"do_tests()");
  printf("[C] We are back in C, the dostring() function returned %d\n",ok);
  printf("\n");
  printf("[C] Let's call lua again, but create an error\n");
  ok=dostring(L,"no_such_function()");
  printf("[C] We are back in C, the dostring() function returned %d\n",ok);
  printf("[C] it should also have returned 1 and printed an error message\n");
  printf("\n");
  printf("[C] Let's call lua again, calling the greeting function\n");
  ok=dostring(L,"call_greeting()");
  printf("[C] This was C=>Lua=>C (getting a bit complex)\n");
  printf("\n");
  printf("[C] all finished, closing the lua state\n");
  lua_close(L);
  return 0;
}
开发者ID:0xb1dd1e,项目名称:swig,代码行数:43,代码来源:embed.c


示例4: iuplua_openlibs

static void iuplua_openlibs (lua_State *L) {
  lua_pushliteral(L, LUA_COPYRIGHT);
  lua_setglobal(L, "_COPYRIGHT");  /* set global _COPYRIGHT */

#ifdef USE_STATIC
  /* disable require */
  dostring(L, "function require() end ", "static_require");

  /* iuplua initialization */
  iuplua_open(L);

#ifdef IUPLUA_IMGLIB
  luaopen_iupluaimglib(L);
#endif
#ifdef IUPLUA_TUIO
  iuptuiolua_open(L);
#endif
#ifdef IUPLUA_WEB
  iupweblua_open(L);
#endif
#ifdef IUPLUA_SCINTILLA
  iup_scintillalua_open(L);
#endif

/* luaopen_lfs(L); */

#ifndef IUPLUA_NO_GL
  iupgllua_open(L);
  iupglcontrolslua_open(L);
#ifdef USE_LUAGL
  luaopen_luagl(L);
#endif
#endif
#ifndef IUPLUA_NO_CD
  iupcontrolslua_open(L);
  iupmatrixexlua_open(L);
  iup_plotlua_open(L);
  cdlua_open(L);
  cdluaiup_open(L);
  cdInitContextPlus();
#endif
#ifndef IUPLUA_NO_IM
  iupimlua_open(L);
  imlua_open(L);
  imlua_open_process(L);
#endif
#ifndef IUPLUA_NO_IM
#ifndef IUPLUA_NO_CD
  cdluaim_open(L);
#endif
#endif
#endif
}
开发者ID:DavidPhillipOster,项目名称:IupCocoa,代码行数:53,代码来源:iup_lua51.c


示例5: include_cpath

	inline void include_cpath(lua_State *L,const char * path)
	{
		std::ostringstream stream;

#ifdef WIN32
		stream << "package.cpath = package.cpath .. \";" << path << "/?.dll\"";
#else
		stream << "package.cpath = package.cpath .. \";" << path << "/?.so\"";
#endif //WIN32

		dostring(L,stream.str().c_str());
	}
开发者ID:zeusever,项目名称:lemonxx-lib,代码行数:12,代码来源:luapi.hpp


示例6: handle_luainit

static int handle_luainit (lua_State *L) {
  const char *name = "=" LUA_INITVERSION;
  const char *init = NULL;
  if (init == NULL) {
    name = "=" LUA_INIT;
	init = NULL;
  }
  if (init == NULL) return LUA_OK;
  else if (init[0] == '@')
    return dofile(L, init+1);
  else
    return dostring(L, init, name);
}
开发者ID:npruehs,项目名称:pinned-down-client-win8,代码行数:13,代码来源:lua.c


示例7: mk_pair

/**
   \brief Parse a block of Lua code. If as_expr is true, then
   it appends the string "return " in front of the script.
*/
void parser_imp::parse_script(bool as_expr) {
    m_last_script_pos = mk_pair(m_scanner.get_script_block_line(), m_scanner.get_script_block_pos());
    if (!m_script_state)
        throw exception("failed to execute Lua script, parser does not have a Lua interpreter");
    std::string script_code = m_scanner.get_str_val();
    if (as_expr) {
        script_code = "return " + script_code;
    }
    next();
    using_script([&](lua_State * L) {
            dostring(L, script_code.c_str());
        });
}
开发者ID:Paradoxika,项目名称:lean,代码行数:17,代码来源:parser_imp.cpp


示例8: handle_luainit

static int handle_luainit (lua_State *L) {
  const char *name = "=" LUA_INITVERSION;
  const char *init = getenv(name + 1);
  if (init == NULL) {
    name = "=" LUA_INIT;
    init = getenv(name + 1);  /* try alternative name */
  }
  if (init == NULL) return LUA_OK;
  else if (init[0] == '@')
    return dofile(L, init+1);
  else
    return dostring(L, init, name);
}
开发者ID:dhrebeniuk,项目名称:linosity,代码行数:13,代码来源:lua.c


示例9: handle_luainit

static int handle_luainit(lua_State *L)
{
#if LJ_TARGET_CONSOLE
  const char *init = NULL;
#else
  const char *init = getenv(LUA_INIT);
#endif
  if (init == NULL)
    return 0;  /* status OK */
  else if (init[0] == '@')
    return dofile(L, init+1);
  else
    return dostring(L, init, "=" LUA_INIT);
}
开发者ID:Nlcke,项目名称:gideros,代码行数:14,代码来源:luajit.c


示例10: set_self_callable

	bool lua_context::execute(const variant& value, game_logic::formula_callable* callable)
	{
		bool res = false;
		if(callable) {
			set_self_callable(*callable);
		}
		if(value.is_string()) {
			res = dostring("", value.as_string());
		} else {
			lua_compiled_ptr compiled = value.try_convert<lua_compiled>();
			ASSERT_LOG(compiled != NULL, "FATAL: object given couldn't be converted to type 'lua_compiled'");
			res = compiled->run(context_ptr());
		}
		return res;
	}
开发者ID:AsKorysti,项目名称:anura,代码行数:15,代码来源:lua_iface.cpp


示例11: handle_luainit

static int handle_luainit (lua_State *L) {
  const char *name = "=" LUA_INITVERSION;
  // getenv not supported on Windows Store
  //const char *init = getenv(name + 1);
  const char *init = NULL;
  if (init == NULL) {
    name = "=" LUA_INIT;
	// getenv not supported on Windows Store
	//init = getenv(name + 1);  /* try alternative name */
    init = NULL;  /* try alternative name */
  }
  if (init == NULL) return LUA_OK;
  else if (init[0] == '@')
    return dofile(L, init+1);
  else
    return dostring(L, init, name);
}
开发者ID:Sparkiy,项目名称:sparkiy-client-w81,代码行数:17,代码来源:lua.c


示例12: runargs

/*
** Processes options 'e' and 'l', which involve running Lua code.
** Returns 0 if some code raises an error.
*/
static int runargs (lua_State *L, char **argv, int n) {
  int i;
  for (i = 1; i < n; i++) {
    int option = argv[i][1];
    lua_assert(argv[i][0] == '-');  /* already checked */
    if (option == 'e' || option == 'l') {
      int status;
      const char *extra = argv[i] + 2;  /* both options need an argument */
      if (*extra == '\0') extra = argv[++i];
      lua_assert(extra != NULL);
      status = (option == 'e')
               ? dostring(L, extra, "=(command line)")
               : dolibrary(L, extra);
      if (status != LUA_OK) return 0;
    }
  }
  return 1;
}
开发者ID:Fabio3rs,项目名称:Guitar-PlusPlus,代码行数:22,代码来源:lua.c


示例13: process_str_request

/*---------------------------------------------------------------------*/
void 
process_str_request(lua_State *L, void *argv)
{
	TRACE_LUA_FUNC_START();
	int read_size, total_read, rc;
	char client_msg[LUA_MAXINPUT];
	int client_sock = *((int *)argv);
	total_read = rc = 0;
	
	/* Receive message from client */
	while ((read_size = recv(client_sock, 
				 &client_msg[total_read],
				 LUA_MAXINPUT - total_read, 0)) > 0) {
		total_read += read_size;
		if ((unsigned)(total_read >= LUA_MAXINPUT) || 
		    client_msg[total_read - 1] == REMOTE_LUA_CMD_DELIM) {
			client_msg[total_read - 1] = '\0';
			break;
		}
	}
	/* 
	 * if total_read == 0, 
	 * then this means that the client closed conn. 
	 *
	 * Otherwise process the lua command
	 */
	if (total_read != 0) {
		char delim = REMOTE_LUA_CMD_DELIM;
		register_lua_procs(L);
		load_startup(L);
		setvbuf(stdout, NULL, _IONBF, BUFSIZ);
		/* redirect stdout and stderr to client_sock */
		dup2(client_sock, 1);
		dup2(client_sock, 2);
		/* redirect command output to the client */
		dostring(L, client_msg, "init");
		rc = write(client_sock, &delim, 1);
		/* redirect stdout and stderr back to /dev/null */
		dup2(0, 1);
		dup2(0, 2);
	}
	TRACE_LUA_FUNC_END();
}
开发者ID:bro,项目名称:packet-bricks,代码行数:44,代码来源:lua_interpreter.c


示例14: runargs

static int runargs(lua_State *L, char **argv, int n)
{
    int i;
    for (i = 1; i < n; i++) {
        if (argv[i] == NULL) continue;
        lua_assert(argv[i][0] == '-');
        switch (argv[i][1]) {  /* option */
        case 'e': {
            const char *chunk = argv[i] + 2;
            if (*chunk == '\0') chunk = argv[++i];
            lua_assert(chunk != NULL);
            if (dostring(L, chunk, "=(command line)") != 0)
                return 1;
            break;
        }
        case 'l': {
            const char *filename = argv[i] + 2;
            if (*filename == '\0') filename = argv[++i];
            lua_assert(filename != NULL);
            if (dolibrary(L, filename))
                return 1;  /* stop if file fails */
            break;
        }
        case 'j': {  /* LuaJIT extension */
            const char *cmd = argv[i] + 2;
            if (*cmd == '\0') cmd = argv[++i];
            lua_assert(cmd != NULL);
            if (dojitcmd(L, cmd))
                return 1;
            break;
        }
        case 'O':  /* LuaJIT extension */
            if (dojitopt(L, argv[i] + 2))
                return 1;
            break;
        case 'b':  /* LuaJIT extension */
            return dobytecode(L, argv+i);
        default:
            break;
        }
    }
    return 0;
}
开发者ID:LuaDist,项目名称:gsl-shell,代码行数:43,代码来源:gsl-shell-jit.c


示例15: handle_luainit

/*---------------------------------------------------------------------*/
static int
handle_luainit(lua_State *L)
{
	TRACE_LUA_FUNC_START();
	
        const char *init = getenv(LUA_INIT);
	
        if (init == NULL) {
		TRACE_LUA_FUNC_END();
		return 0; /* status OK */
	}
        else if (init[0] == '@') {
		TRACE_LUA_FUNC_END();
                return dofile(L, init+1);
	} else
                dostring(L, init, "=" LUA_INIT);
	
	TRACE_LUA_FUNC_END();
        return 0;
}
开发者ID:bro,项目名称:packet-bricks,代码行数:21,代码来源:lua_interpreter.c


示例16: runargs

static int runargs(lua_State *L, char **argv, int n)
{
    int i;

    for (i = 1; i < n; i++)
    {
        lua_assert(argv[i][0] == '-');

        switch (argv[i][1]) /* option */
        {
        case 'e': {
            const char *chunk = argv[i] + 2;
            if (*chunk == '\0')
                chunk = argv[++i];

            lua_assert(chunk != NULL);
            if (dostring(L, chunk, "=(command line)") != LUA_OK)
                return 0;

            break;
        }

        case 'l': {
            const char *filename = argv[i] + 2;
            if (*filename == '\0')
                filename = argv[++i];

            lua_assert(filename != NULL);
            if (dolibrary(L, filename) != LUA_OK)
                return 0; /* stop if file fails */

            break;
        }

        default: break;
        }
    }

    return 1;
}
开发者ID:hyyh619,项目名称:OpenSceneGraph-3.4.0,代码行数:40,代码来源:lua.c


示例17: runargs

static int runargs (lua_State *L, char **argv, int n)
{
	int i;
	for (i = 1; i < n; i++) {
		if (argv[i] == NULL) continue;
		lua_assert(argv[i][0] == '-');
		switch (argv[i][1]) {  /* option */
		case 'e': {
			const char *chunk = argv[i] + 2;
			if (*chunk == '\0') chunk = argv[++i];
			lua_assert(chunk != NULL);
			if (dostring(L, chunk, "=(command line)") != 0)
				return 1;
			break;
		}
		case 'm': {
			const char *limit = argv[i] + 2;
			int memlimit=0;
			if (*limit == '\0') limit = argv[++i];
			lua_assert(limit != NULL);
			memlimit = atoi(limit);
			lua_gc(L, LUA_GCSETMEMLIMIT, memlimit);
			break;
		}
		case 'l': {
			const char *filename = argv[i] + 2;
			if (*filename == '\0') filename = argv[++i];
			lua_assert(filename != NULL);
			if (dolibrary(L, filename))
				return 1;  /* stop if file fails */
			break;
		}
		default:
			break;
		}
	}
	return 0;
}
开发者ID:Amalinda,项目名称:ruuvitracker_fw,代码行数:38,代码来源:lua.c


示例18: handle_argv

static int handle_argv (char *argv[], int *interactive) {
  if (argv[1] == NULL) {  /* no more arguments? */
    if (stdin_is_tty()) {
      print_version();
      manual_input();
    }
    else
      file_input(NULL);  /* executes stdin as a file */
  }
  else {  /* other arguments; loop over them */
    int i;
    for (i = 1; argv[i] != NULL; i++) {
      if (argv[i][0] != '-') break;  /* not an option? */
      switch (argv[i][1]) {  /* option */
        case '-': {  /* `--' */
          if (argv[i][2] != '\0') {
            print_usage();
            return 1;
          }
          i++;  /* skip this argument */
          goto endloop;  /* stop handling arguments */
        }
        case '\0': {
          file_input(NULL);  /* executes stdin as a file */
          break;
        }
        case 'i': {
          *interactive = 1;
          break;
        }
        case 'v': {
          print_version();
          break;
        }
        case 'e': {
          const char *chunk = argv[i] + 2;
          if (*chunk == '\0') chunk = argv[++i];
          if (chunk == NULL) {
            print_usage();
            return 1;
          }
          if (dostring(chunk, "=<command line>") != 0)
            return 1;
          break;
        }
        case 'l': {
          const char *filename = argv[i] + 2;
          if (*filename == '\0') filename = argv[++i];
          if (filename == NULL) {
            print_usage();
            return 1;
          }
          if (load_file(filename))
            return 1;  /* stop if file fails */
          break;
        }
        case 'c': {
          l_message(progname, "option `-c' is deprecated");
          break;
        }
        case 's': {
          l_message(progname, "option `-s' is deprecated");
          break;
        }
        default: {
          print_usage();
          return 1;
        }
      }
    } endloop:
    if (argv[i] != NULL) {
      const char *filename = argv[i];
      getargs(argv, i);  /* collect arguments */
      lua_setglobal(L, "arg");
      return file_input(filename);  /* stop scanning arguments */
    }
  }
  return 0;
}
开发者ID:sunaku,项目名称:swig-ruby-ffi,代码行数:79,代码来源:lua.c


示例19: pmain

static int pmain(lua_State *L)
{
  struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
  char **argv = s->argv;
  int script;
  int flags = 0;
  globalL = L;
  if (argv[0] && argv[0][0]) progname = argv[0];
  LUAJIT_VERSION_SYM();  /* linker-enforced version check */
  script = collectargs(argv, &flags);
  if (script < 0) {  /* invalid args? */
    print_usage();
    s->status = 1;
    return 0;
  }
  if ((flags & FLAGS_NOENV)) {
    lua_pushboolean(L, 1);
    lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
  }
  lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
  luaL_openlibs(L);  /* open libraries */

  /**************/
  lua_pushstring(L, MULTIWIICL_VERSION);
  lua_setglobal(L, "MULTIWIICL_VERSION");

  extern int luaopen_lpeg(lua_State*);
  lua_pushcfunction(L, luaopen_lpeg);
  lua_call(L, 0, 0);

  extern int luaopen_luaserial(lua_State*);
  lua_pushcfunction(L, luaopen_luaserial);
  lua_call(L, 0, 0);

  extern int luaopen_linenoise(lua_State*);
  lua_pushcfunction(L, luaopen_linenoise);
  lua_call(L, 0, 1);

# include "Config.h"
  if (dostring(L, (const char*)Config, "@Config")) {
    printf("%s\n", lua_tostring(L, -1));
    lua_pop(L, 1);
  }

# include "MultiWii.h"
  if (dostring(L, (const char*)MultiWii, "@MultiWii")) {
    printf("%s\n", lua_tostring(L, -1));
    lua_pop(L, 1);
  }

  /**************/

  lua_gc(L, LUA_GCRESTART, -1);
  if (!(flags & FLAGS_NOENV)) {
    s->status = handle_luainit(L);
    if (s->status != 0) return 0;
  }

  s->status = runargs(L, argv, (script > 0) ? script : s->argc);
  if (s->status != 0) return 0;
  if (script) {
    s->status = handle_script(L, argv, script);
    if (s->status != 0) return 0;
  }

  if ((flags & FLAGS_INTERACTIVE) || (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION)))) {
#   include "Prompt.h"
    if (dostring(L, (const char*)Prompt, "@Prompt")) {
      printf("%s\n", lua_tostring(L, -1));
      lua_pop(L, 1);
    }
  }

//  if ((flags & FLAGS_VERSION)) print_version();
//  s->status = runargs(L, argv, (script > 0) ? script : s->argc);
//  if (s->status != 0) return 0;
//  if (script) {
//    s->status = handle_script(L, argv, script);
//    if (s->status != 0) return 0;
//  }
//  if ((flags & FLAGS_INTERACTIVE)) {
//    print_jit_status(L);
//    dotty(L);
//  } else if (script == 0 && !(flags & (FLAGS_EXEC|FLAGS_VERSION))) {
//    if (lua_stdin_is_tty()) {
//      print_version();
//      print_jit_status(L);
//      dotty(L);
//    } else {
//      dofile(L, NULL);  /* executes stdin as a file */
//    }
//  }
  return 0;
}
开发者ID:c---,项目名称:MultiWiiCL,代码行数:94,代码来源:luajit.c


示例20: handle_argv

static int handle_argv (lua_State *L, int argc, char **argv, int *interactive) {
  if (argv[1] == NULL) {  /* no arguments? */
    *interactive = 0;
    if (lua_stdin_is_tty())
      dotty(L);
    else
      dofile(L, NULL);  /* executes stdin as a file */
  }
  else {  /* other arguments; loop over them */
    int i;
    for (i = 1; argv[i] != NULL; i++) {
      if (argv[i][0] != '-') break;  /* not an option? */
      switch (argv[i][1]) {  /* option */
        case '-': {  /* `--' */
          if (argv[i][2] != '\0') {
            print_usage();
            return 1;
          }
          i++;  /* skip this argument */
          goto endloop;  /* stop handling arguments */
        }
        case '\0': {
          clearinteractive(interactive);
          dofile(L, NULL);  /* executes stdin as a file */
          break;
        }
        case 'i': {
          *interactive = 2;  /* force interactive mode after arguments */
          break;
        }
        case 'v': {
          clearinteractive(interactive);
          print_version();
          break;
        }
        case 'e': {
          const char *chunk = argv[i] + 2;
          clearinteractive(interactive);
          if (*chunk == '\0') chunk = argv[++i];
          if (chunk == NULL) {
            print_usage();
            return 1;
          }
          if (dostring(L, chunk, "=(command line)") != 0)
            return 1;
          break;
        }
        case 'l': {
          const char *filename = argv[i] + 2;
          if (*filename == '\0') filename = argv[++i];
          if (filename == NULL) {
            print_usage();
            return 1;
          }
          if (dolibrary(L, filename))
            return 1;  /* stop if file fails */
          break;
        }
        default: {
          clearinteractive(interactive);
          print_usage();
          return 1;
        }
      }
    } endloop:
    if (argv[i] != NULL) {
      int status;
      const char *filename = argv[i];
      int narg = getargs(L, argc, argv, i);  /* collect arguments */
      lua_setglobal(L, "arg");
      clearinteractive(interactive);
      status = luaL_loadfile(L, filename);
      lua_insert(L, -(narg+1));
      if (status == 0)
        status = docall(L, narg, 0);
      else
        lua_pop(L, narg);      
      return report(L, status);
    }
  }
  return 0;
}
开发者ID:LuaDist,项目名称:oil,代码行数:82,代码来源:console.c



注:本文中的dostring函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ dot函数代码示例发布时间:2022-05-30
下一篇:
C++ dooptions函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap