예제 #1
0
파일: lua.c 프로젝트: benlaurie/ldns
int
main(int argc, char *argv[])
{
	if (argc != 2) {
		usage(stderr, argv[0]);
		exit(EXIT_FAILURE);
	}

	if (access(argv[1], R_OK)) {
		fprintf(stderr, "File %s is unavailable.\n", argv[1]);
		exit(EXIT_FAILURE);
	}
	
        L = lua_open();
        lua_baselibopen(L);
	luaopen_math(L);
	luaopen_io(L);
	luaopen_string(L);

	register_ldns_functions();

        /* run the script */
        lua_dofile(L, argv[1]);

        lua_close(L);
        exit(EXIT_SUCCESS);
}
예제 #2
0
파일: lua.c 프로젝트: xiaobinshe/multitv
static void userinit (void) {
  lua_baselibopen(L);
  lua_iolibopen(L);
  lua_strlibopen(L);
  lua_mathlibopen(L);
  lua_dblibopen(L);
  /* add your libraries here */
}
예제 #3
0
void lua_init()
{
	g_pLuaVm = lua_open();
	lua_baselibopen(g_pLuaVm);
	lua_tablibopen(g_pLuaVm);
	lua_iolibopen(g_pLuaVm);
	lua_strlibopen(g_pLuaVm);
	lua_mathlibopen(g_pLuaVm);
	register_lua_functions(g_pLuaVm);

	g_pEffectLuaVm = lua_open();
	lua_baselibopen(g_pEffectLuaVm);
	lua_tablibopen(g_pEffectLuaVm);
	lua_iolibopen(g_pEffectLuaVm);
	lua_strlibopen(g_pEffectLuaVm);
	lua_mathlibopen(g_pEffectLuaVm);
	register_lua_functions(g_pEffectLuaVm);
}
예제 #4
0
int InitScripting(DISZ80 *d)
{
	char	buf[256];
	int		err;

	if (d->ls == NULL)
		{
		d->ls = lua_open(0);

		if (d->ls == NULL)
			return DERR_OUTOFMEM;
		
		lua_baselibopen(d->ls);
		lua_strlibopen(d->ls);

		lua_pushuserdata(d->ls, d);
		lua_setglobal(d->ls, "DISZ80STRUC");

		lua_register(d->ls, LUA_ERRORMESSAGE, LuaErrorHandler);

/* Register the dZ80 support functions */
		lua_register(d->ls, "d_RegTrap",		d_RegTrap);
		lua_register(d->ls, "d_AddComment", 	d_AddComment);
		lua_register(d->ls, "d_AddToDis",		d_AddToDis);
		lua_register(d->ls, "d_AddToDisTab",	d_AddToDisTab);
		lua_register(d->ls, "d_GetByte",		d_GetByte);
		lua_register(d->ls, "d_LookByte",		d_LookByte);
		lua_register(d->ls, "d_DB", 			d_DB);
		lua_register(d->ls, "d_FlushLine",		d_FlushLine);
		lua_register(d->ls, "d_IsCodeByte",		d_IsCodeByte);
		lua_register(d->ls, "d_GetPC",			d_GetPC);
		lua_register(d->ls, "d_LookByteAddr",	d_LookByteAddr);
		lua_register(d->ls, "d_GetPass",		d_GetPass);
		lua_register(d->ls, "d_Message",		d_Message);

/* Register the general support functions */
		lua_register(d->ls, "hex",				d_FromHex);

/* Set up the trap registration functions */
		sprintf(buf,
			"__dz80_pre={}\n"
			"__dz80_post={}\n"
			"function d_PreTrap(op, fn) __dz80_pre[op]=fn d_RegTrap(op, %d) end\n"
			"function d_PostTrap(op, fn) __dz80_post[op]=fn d_RegTrap(op, %d) end\n",
			D_SCRIPT_PRE, D_SCRIPT_POST);

		err = lua_dostring(d->ls, buf);
		if (err)
			return DERR_SCRIPTERROR;
		}

	return DERR_NONE;
}
예제 #5
0
void context_new_VM(context_t * context)
{
	context_lock_list();
	context->luaVM = lua_open();
	lua_baselibopen(context->luaVM);
	lua_tablibopen(context->luaVM);
	lua_iolibopen(context->luaVM);
	lua_strlibopen(context->luaVM);
	lua_mathlibopen(context->luaVM);

	register_lua_functions(context);
	context_unlock_list();
}
예제 #6
0
파일: main.cpp 프로젝트: OSUser/avbot
lua_state::lua_state()
    : m_state(lua_open())
{
    luaopen_base(m_state);
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
	 // lua 5.1 or newer
	 luaL_openlibs(m_state);
#else
	 // lua 5.0.2 or older
    lua_baselibopen(m_state);
#endif
    m_top = lua_gettop(m_state);
    luabind::open(m_state);
}
예제 #7
0
파일: colua.c 프로젝트: neechbear/colloquy
static void userinit (void) {
  lua_baselibopen(L);
  lua_iolibopen(L);
  lua_strlibopen(L);
  lua_mathlibopen(L);
  lua_dblibopen(L);
  /* add your libraries here */
  lua_socketlibopen(L);
  md5lib_open(L);
  wrap_register(L);
  ltime_register(L);
  luaopen_posix(L);
  drop_register(L);
}
예제 #8
0
classLUA::classLUA (int iStackSize)
{
	m_pState = lua_open (0);

    if ( m_pState ) 
	{
        lua_baselibopen(m_pState);
        lua_mathlibopen(m_pState);
        lua_iolibopen(m_pState);
    }

    m_pBuffer = NULL;
	m_lBufferSize = 0;
}
예제 #9
0
int main(void)
{
 int rc;
 L=lua_open(0);
 lua_baselibopen(L);
 lua_iolibopen(L);
 lua_strlibopen(L);
 lua_mathlibopen(L);
 lua_dblibopen(L);
 start_trace(stderr);
 rc=lua_dofile(L,0);
 stop_trace();
 return rc;
}
예제 #10
0
Script::Script (bool initStandardLibrary) :
	m_ownState(false)
{
	m_state = lua_open(0);
	m_ownState = true;
	if (initStandardLibrary)
		lua_baselibopen(m_state);

	// Register some basic functions with Lua.
	Register("LOG", Script_LOG);
	Register("_ERRORMESSAGE", Script_LOG);
	DoString(LuaScript_CopyTable);
//	lua_setfatalerrorhandler(FatalError);
}
예제 #11
0
kgmLuaScript::kgmLuaScript(kgmIResources *r)
{
  resources = r;

  handler = lua_open(0);

  if(!handler)
    return;

  lua_baselibopen (handler);
  //lua_iolibopen (handler);
  lua_strlibopen (handler);
  lua_mathlibopen (handler);
  //lua_dblibopen (handler);
}
예제 #12
0
파일: lua.c 프로젝트: bcasiello/muw
int main(int argc, char *argv[])
{
    /* initialize Lua */
    lua_State *L = lua_open(0);

    /* open libraries */
    lua_baselibopen(L);
    lua_iolibopen(L);
    lua_strlibopen(L);
    lua_mathlibopen(L);
    lua_socketlibopen(L);
    lua_muwlibopen(L);

    /* execute the specified file */
    return lua_dofile(L, argv[1]);
}
예제 #13
0
파일: init.c 프로젝트: btbytes/examples
int main(int argc, char *argv[])
{
    /* initialize Lua */
    L = lua_open();

    /* load various Lua libraries */
    lua_baselibopen(L);
    luaopen_table(L);
    luaopen_io(L);
    luaopen_string(L);
    luaopen_math(L);

    /* cleanup Lua */
    lua_close(L);

    return 0;
}
예제 #14
0
void AvHScriptInstance::Init()
{
	this->mState = lua_open();
	
	lua_baselibopen(this->mState);
	lua_strlibopen(this->mState);
	lua_mathlibopen(this->mState);
	//lua_iolibopen(this->mState);

	this->InitShared();

	#ifdef AVH_SERVER
	this->InitServer();
	#else
	this->InitClient();
	#endif
}
예제 #15
0
bool kgmLuaOpen()
{
  if(lua_main)
    return false;

  lua_main = lua_open(0);

  if(!lua_main)
    return false;


  lua_baselibopen (lua_main);
  lua_iolibopen (lua_main);
  lua_strlibopen (lua_main);
  lua_mathlibopen (lua_main);
  lua_dblibopen (lua_main);

  return true;
}
예제 #16
0
/*
** Python prototype: "lua_state <-- lua_open([stack_size])"
** opens a Lua State and returns it to Python
** accepts an optional parameter informing the size of the stack Lua should use
** (measured in number of elements)
*/
static PyObject *Py_lua_open(PyObject *self, PyObject *args) {
lua_State *L;
int stack_size = 0;
PyObject *result = NULL;

   if (PyArg_ParseTuple(args, "|i:lua_open", &stack_size)) {
      L = lua_open(stack_size);
      lua_baselibopen(L);
      lua_iolibopen(L);
      lua_strlibopen(L);
      lua_mathlibopen(L);
      lua_dblibopen(L);

      lua_register(L, "_LuaPy_callPythonFunction", Lua_callPythonFunction);
      lua_register(L, "_LuaPy_setErrorMessage",    Lua_setErrorMessage);
      lua_dostring(L, LUA_init_state);
      result = Py_BuildValue("i", L);
   }
   return result;
}
int main (int argc, char *argv[])
{
  int i;

  OleInitialize(NULL);

  SetConsoleTitle(LUACOM_VERSION);

#if defined(LUA4)
  lua_State *lua_state = lua_open(0);
  lua_baselibopen (lua_state);
  lua_mathlibopen (lua_state);
  lua_iolibopen   (lua_state);
  lua_strlibopen (lua_state);
#elif defined(LUA5)
  lua_State *lua_state = lua_open();
  luaopen_base (lua_state);
  luaopen_math (lua_state);
  luaopen_io   (lua_state);
  luaopen_string (lua_state);
  luaopen_table (lua_state);
#endif

  lua_pushstring(lua_state, "> "); lua_setglobal(lua_state, "_PROMPT");

  luacom_open(lua_state);
  init_windows(lua_state);
  if (argc < 2) {  /* no arguments? */
    if (isatty(0)) {
      printf("%s  %s\n", LUACOM_VERSION, LUACOM_COPYRIGHT);
      manual_input(lua_state, 1);
    }
    else
      ldo(lua_state, lua_dofile, NULL);  /* executes stdin as a file */
  }
  else for (i=1; i<argc; i++) {
    if (argv[i][0] == '-') {  /* option? */
      switch (argv[i][1]) {
        case 0:
          ldo(lua_state, lua_dofile, NULL);  /* executes stdin as a file */
          break;
        case 'i':
          manual_input(lua_state, 1);
          break;
        case 'q':
          manual_input(lua_state, 0);
          break;
        case 'v':
          printf("%s  %s\n(written by %s)\n\n",
                 LUACOM_VERSION, LUACOM_COPYRIGHT, LUACOM_AUTHORS);
          break;
        case 'e':
          i++;
          if (ldo(lua_state, lua_dostring, argv[i]) != 0) {
            fprintf(stderr, "lua: error running argument `%s'\n", argv[i]);
            return 1;
          }
          break;
        default:
          print_message();
          exit(1);
      }
    }
    else if (strchr(argv[i], '='))
      assign(lua_state, argv[i]);
    else {
      int result = ldo(lua_state, lua_dofile, argv[i]);
      if (result) {
        if (result == 2) {
          fprintf(stderr, "lua: cannot execute file ");
          perror(argv[i]);
        }
        exit(1);
      }
    }
  }

  luacom_close(lua_state);
  lua_close(lua_state);

  OleUninitialize();

  return 0;
}
예제 #18
0
int main()
{
    lua_State* L = lua_open();
    luaopen_base(L);
#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 501
	 // lua 5.1 or newer
	 luaL_openlibs(L);
#else
	 // lua 5.0.2 or older
    lua_baselibopen(L);
#endif
    luabind::open(L);

    luabind::module(L, "namespace")
    [
        luabind::def("HelloWorld", (void(*)())&HelloWorld),
        luabind::def("HelloWorld", (void(*)(const std::string&))&HelloWorld),
        luabind::def("HelloWorld", (void(*)(const int))&HelloWorld),
        luabind::class_<MyClass>("MyClass")
            .def(luabind::constructor<>())
            .def("Hello", (void(MyClass::*)()) &MyClass::Hello)
            .def("Hello", (void(MyClass::*)(const std::string&)) &MyClass::Hello)
            .scope
            [
                luabind::class_<MyOtherClass>("MyOtherClass")
                    .property("num", &MyOtherClass::num)
            ]
    ];

    lua_register(L, "GetLuabindInfo", &GetLuabindInfo);

    try
    {

        dostring(L,
                 "assert(GetLuabindInfo() == nil)\n"
                 "assert(GetLuabindInfo(1) == nil)\n"
                 "assert(GetLuabindInfo(\"test\") == nil)\n"

                 "testUs = {namespace.HelloWorld, namespace.MyClass, namespace.MyClass.MyOtherClass}\n"
                 "for index, testMe in ipairs(testUs) do\n"
                 " info = GetLuabindInfo(testMe)\n"
                 " if not info then\n"
                 "  print(\"entry \" .. index .. \" is no luabind function/class\")\n"
                 " else\n"
                 "  print(\"entry \" .. index .. \" is a \" .. info.type .. \" called \" .. (info.name or \"\"))\n"
                 "  if info.type == \"function\" then\n"
                 "   print(\"available overloads:\")\n"
                 "   for _, signature in ipairs(info.overloads) do\n"
                 "    print(signature)\n"
                 "   end\n"
                 "  else\n"
                 "   assert(info.type == \"class\")\n"
                 "  end\n"
                 " end\n"
                 " print()\n"
                 "end\n"
                 "namespace.HelloWorld{}\n" //this prints the correct signature in the error
                 );
    }
    catch(std::string err)
    {
        std::cout<<"Caught error: " << err << std::endl;
    }

    lua_close(L);
    return 0;
}
예제 #19
0
파일: tolua.c 프로젝트: AmyBSOD/ToME-SX
int main (int argc, char* argv[])
{
 lua_State* L = lua_open(0);
 lua_baselibopen(L);
 lua_iolibopen(L);
 lua_strlibopen(L);
 lua_pushstring(L,TOLUA_VERSION); lua_setglobal(L,"TOLUA_VERSION");

 if (argc==1)
 {
  help();
  return 0;
 }
 else
 {
  int i, t;
  lua_newtable(L);
  lua_pushvalue(L,-1);
  lua_setglobal(L,"flags");
  t = lua_gettop(L);
  for (i=1; i<argc; ++i)
  {
   if (*argv[i] == '-')
   {
    switch (argv[i][1])
    {
     case 'v': version(); return 0;
     case 'h': help(); return 0;
     case 'p': setfield(L,t,"p",""); break;
     case 'P': setfield(L,t,"P",""); break;
     case 'o': setfield(L,t,"o",argv[++i]); break;
     case 'n': setfield(L,t,"n",argv[++i]); break;
     case 'H': setfield(L,t,"H",argv[++i]); break;
     default: error(argv[i]); break;
    }
   }
   else
   {
    setfield(L,t,"f",argv[i]);
    break;
   }
  }
  lua_pop(L,1);
 }

#if 1
 {
  int tolua_tolualua_open(lua_State* L);
  tolua_tolualua_open(L);
 }
#else
 {
  int i;
  char* p;
  char  path[BUFSIZ];
  char* files[] = {
                   "basic.lua",
                   "feature.lua",
                   "verbatim.lua",
                   "code.lua",
                   "typedef.lua",
                   "container.lua",
                   "package.lua",
                   "module.lua",
                   "define.lua",
                   "enumerate.lua",
                   "declaration.lua",
                   "variable.lua",
                   "array.lua",
                   "function.lua",
                   "operator.lua",
                   "class.lua",
                   "clean.lua",
                   "doit.lua",
                   NULL
                  };
  strcpy(path,argv[0]);
  p = strrchr(path,'/');
  p = (p==NULL) ? path : p+1;
  for (i=0; files[i]; ++i)
  {
   sprintf(p,"%s",files[i]);
   lua_dofile(L,path); 
  }
 }

#endif
 return 0;
}