当前位置: 首页>>代码示例>>C++>>正文


C++ dostring函数代码示例

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


在下文中一共展示了dostring函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例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


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