예제 #1
0
/* 示例1:简单获取lua的全局变量 */
void HelloLua::demo1() {
    lua_State* pL = lua_open();
    luaopen_base(pL);
    luaopen_math(pL);
    luaopen_string(pL);

    /* 执行Lua脚本,返回0代表成功 */
    int err = luaL_dofile(pL, "helloLua.lua");
    CCLOG("open : %d", err);

    /* 重置栈顶索引 */
    lua_settop(pL, 0);
    lua_getglobal(pL, "myName");

    /* 判断栈顶的值的类型是否为String, 返回非0值代表成功 */
    int isstr = lua_isstring(pL, 1);
    CCLOG("isstr = %d", isstr);

    /* 获取栈顶的值 */
    const char* str = lua_tostring(pL, 1);
    CCLOG("getStr = %s", str);

    /* 清除字符串 */
    lua_pop(pL, 1);

    lua_close(pL);
}
예제 #2
0
파일: ltapi.c 프로젝트: acassis/lintouch
int ltapi_libraries_load( lua_State * L )
{
    /* load required library and discard any possible results remaining at
     * the stack */

    luaopen_base( L );
    lua_settop( L, 0 );

    luaopen_table( L );
    lua_settop( L, 0 );

    luaopen_io( L );
    lua_settop( L, 0 );

    luaopen_string( L );
    lua_settop( L, 0 );

    luaopen_math( L );
    lua_settop( L, 0 );

    luaopen_debug( L );
    lua_settop( L, 0 );

    luaopen_loadlib( L );
    lua_settop( L, 0 );

    return 0;
}
예제 #3
0
/***********************************************************
constructor
***********************************************************/
LuaHandlerBase::LuaHandlerBase()
    : m_creatingthread(-1)
{
    try
    {
        // Create a new lua state
        m_LuaState = lua_open();

        // Connect LuaBind to this lua state
        luabind::open(m_LuaState);

        //open standard libs
        luaopen_base(m_LuaState);
        luaopen_table(m_LuaState);
        luaopen_string(m_LuaState);
        luaopen_math(m_LuaState);
        luaopen_debug(m_LuaState);
        //luaopen_package(m_LuaState);

        //luaL_openlibs(m_LuaState);
    }
    catch(const std::exception &error)
    {
        LogHandler::getInstance()->LogToFile(std::string("Exception initializing LUA for base lua: ") + error.what(), 0);
    }
}
예제 #4
0
bool LuaState::LoadStringLibrary()
{
    luaopen_string(this->L);
    lua_pop(this->L, 1);

    return true;
}
예제 #5
0
    void LuaLibrary::VLoadCoreModule(
                const unsigned int selectedModule)
    {
        CoreModules coreModule =
                        static_cast<CoreModules>(selectedModule);
        
        switch(coreModule)
        {
            case LuaLibrary::CoreModules::Base:
                luaopen_base(m_pLuaState);
                break;
            
            case LuaLibrary::CoreModules::Debug:
                luaopen_debug(m_pLuaState);
                break;
                
            case LuaLibrary::CoreModules::Math:
                luaopen_math(m_pLuaState);
                break;

            case LuaLibrary::CoreModules::Os:
                luaopen_os(m_pLuaState);
                break;
                
            case LuaLibrary::CoreModules::String:
                luaopen_string(m_pLuaState);
                break;
                
            case LuaLibrary::CoreModules::Table:
                luaopen_table(m_pLuaState);
                break;
        }
    }
예제 #6
0
ActionScript::ActionScript(Game *igame,const std::string &datadir,const std::string &scriptname):
game(igame),
_player(NULL)
{
	this->loaded = false;
	lastuid = 0;
	if(scriptname == "")
		return;
	luaState = lua_open();
	luaopen_loadlib(luaState);
	luaopen_base(luaState);
	luaopen_math(luaState);
	luaopen_string(luaState);
	luaopen_io(luaState);
    lua_dofile(luaState, std::string(datadir + "actions/lib/actions.lua").c_str());

#ifdef USING_VISUAL_2005
	FILE* in = NULL;
	fopen_s(&in, scriptname.c_str(), "r");
#else
	FILE* in=fopen(scriptname.c_str(), "r");
#endif //USING_VISUAL_2005
	if(!in){
		std::cout << "Error: Can not open " << scriptname.c_str() << std::endl;
		return;
	}
	else
		fclose(in);
	lua_dofile(luaState, scriptname.c_str());
	this->setGlobalNumber("addressOfActionScript", (int)this);
	this->loaded = true;
	this->registerFunctions();
}
예제 #7
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);
}
예제 #8
0
파일: script.c 프로젝트: ryjen/muddled
void init_lua()
{
    lua_instance = lua_open();
    luaopen_base(lua_instance);
    luaopen_string(lua_instance);

}
예제 #9
0
파일: lua.c 프로젝트: dsturnbull/gravit
int luaInit() {

    luaFree();

    state.lua = lua_open();
    if (!state.lua) {
        conAdd(LERR, "Error loading LUA");
        return 0;
    }
    
    luaL_openlibs(state.lua);
    luaopen_base(state.lua);
    luaopen_table(state.lua);
    luaopen_string(state.lua);
    luaopen_math(state.lua);

#define AddFunction(a,b) lua_pushcfunction(state.lua, b); lua_setglobal(state.lua, a);

    AddFunction("particle", luag_spawn)
    AddFunction("log", luag_log)
    AddFunction("load", luag_load);

    return 1;

}
//============================================================================
// bool CLuaVirtualMachine::InitialiseVM
//---------------------------------------------------------------------------
// Initialises the VM, open lua, makes sure things are OK
//
// Parameter   Dir      Description
// ---------   ---      -----------
// None.
//
// Return
// ------
// Success.
//
//============================================================================
bool CLuaVirtualMachine::InitialiseVM (void)
{
   // Open Lua!
   if (Ok ()) DestroyVM ();

   m_pState = lua_open ();

   if (m_pState) 
   {
      m_fIsOk = true;

      // Load util libs into lua
      luaopen_base (m_pState);
      luaopen_table (m_pState);
      luaopen_string (m_pState);
      luaopen_math (m_pState);
      luaopen_debug (m_pState);
      //luaopen_io (m_pState);
      //luaopen_loadlib (m_pState);

      // setup global printing (trace)
      lua_pushcclosure (m_pState, printMessage, 0);
      lua_setglobal (m_pState, "trace");

      lua_atpanic (m_pState, (lua_CFunction) CLuaVirtualMachine::Panic);

      return true;
   }

   return false;
}
예제 #11
0
파일: luatest.c 프로젝트: zoe01/function
int main(void) {
	char buff[256];
	char buf[256];
	int error;
	lua_State *L = luaL_newstate();
	luaL_openlibs(L);
	luaopen_base(L);             /* opens the basic library */
	luaopen_table(L);            /* opens the table library */
	luaopen_io(L);               /* opens the I/O library */
	luaopen_string(L);           /* opens the string lib. */
	luaopen_math(L);             /* opens the math lib. */
	char s1[] = "lzkx";
	char s2 = "zny";
	printf("input: ddd\n");
	sacnf_s();
	while (fgets(buff, sizeof(buff), stdin) != NULL) {
  		sprintf_s(buf,256, "print ( %s)", buff,256);
		error = luaL_loadbuffer(L, buf, strlen(buf), "line") ||
			lua_pcall(L, 0, 0, 0);
		if (error) {
			fprintf(stderr, "%s", lua_tostring(L, -1));
			lua_pop(L, 1);  /* pop error message from the stack */
			
		}

	}

	lua_close(L);
	return 0;

}
예제 #12
0
파일: embed2.c 프로젝트: charlie5/swig4ada
int main(int argc,char* argv[]) {
  lua_State *L;
  int ok;
  int res;
  char str[80];
  printf("[C] Welcome to the simple embedded Lua example v2\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 wrappered library\n");
  luaopen_example(L);
  printf("[C] all looks ok\n");
  printf("\n");
  printf("[C] lets load the file 'runme.lua'\n");
  printf("[C] any lua code in this file will be executed\n");
  if (luaL_loadfile(L, "runme.lua") || 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] lets call the Lua function 'add(1,1)'\n");
  printf("[C] using the C function 'call_add'\n");
  ok=call_add(L,1,1,&res);
  printf("[C] the function returned %d with value %d\n",ok,res);
  printf("\n");
  printf("[C] lets do this rather easier\n");
  printf("[C] we will call the same Lua function using a generic C function 'call_va'\n");
  ok=call_va(L,"add","ii>i",1,1,&res);
  printf("[C] the function returned %d with value %d\n",ok,res);
  printf("\n");
  printf("[C] we will now use the same generic C function to call 'append(\"cat\",\"dog\")'\n");
  ok=call_va(L,"append","ss>s","cat","dog",str);
  printf("[C] the function returned %d with value %s\n",ok,str);
  printf("\n");
  printf("[C] we can also make some bad calls to ensure the code doesn't fail\n");
  printf("[C] calling adds(1,2)\n");
  ok=call_va(L,"adds","ii>i",1,2,&res);
  printf("[C] the function returned %d with value %d\n",ok,res);
  printf("[C] calling add(1,'fred')\n");
  ok=call_va(L,"add","is>i",1,"fred",&res);
  printf("[C] the function returned %d with value %d\n",ok,res);
  printf("\n");
  printf("[C] Note: no protection if you mess up the va-args, this is C\n");
  printf("\n");
  printf("[C] Finally we will call the wrappered gcd function gdc(6,9):\n");
  printf("[C] This will pass the values to Lua, then call the wrappered function\n");
  printf("    Which will get the values from Lua, call the C code \n");
  printf("    and return the value to Lua and eventually back to C\n");
  printf("[C] Certainly not the best way to do it :-)\n");
  ok=call_va(L,"gcd","ii>i",6,9,&res);
  printf("[C] the function returned %d with value %d\n",ok,res);
  printf("\n");
  printf("[C] all finished, closing the lua state\n");
  lua_close(L);
  return 0;
}
예제 #13
0
파일: LuaPlus.cpp 프로젝트: brock7/TianLong
void LuaState::Init( bool initStandardLibrary )
{
	// Register some basic functions with Lua.
	if (initStandardLibrary)
	{
		// A "bug" in Lua 5.01 causes stack entries to be left behind.
		LuaAutoBlock autoBlock(this);
		luaopen_base(m_state);
		luaopen_table( m_state );
		luaopen_io(m_state);
		luaopen_string(m_state);
		luaopen_wstring(m_state);
		luaopen_math(m_state);
		luaopen_debug(m_state);
#ifndef _WIN32_WCE
		luaopen_loadlib(m_state);
#endif _WIN32_WCE

		ScriptFunctionsRegister( this );

		GetGlobals().Register("LuaDumpGlobals", LS_LuaDumpGlobals);
		GetGlobals().Register("LuaDumpObject", LS_LuaDumpObject);
		GetGlobals().Register("LuaDumpFile", LS_LuaDumpFile);
	}

	GetGlobals().Register("LOG", LS_LOG);
	GetGlobals().Register("_ALERT", LS_LOG);

	lua_atpanic( m_state, FatalError );
}
예제 #14
0
파일: g_lua.c 프로젝트: otty/cake3
/*
============
G_InitLua
============
*/
void G_InitLua()
{
	char            buf[MAX_STRING_CHARS];
	char			filename[MAX_QPATH];
	
	G_Printf("------- Lua Initialization -------\n");

	g_luaState = lua_open();

	// Lua standard lib
	luaopen_base(g_luaState);
	luaopen_string(g_luaState);

	// Quake lib
	luaopen_entity(g_luaState);
	luaopen_game(g_luaState);
	luaopen_qmath(g_luaState);
	luaopen_vector(g_luaState);
	
	// load map specific Lua script as default
	trap_Cvar_VariableStringBuffer("mapname", buf, sizeof(buf));
	Com_sprintf(filename, sizeof(filename), "scripts/lua/%s.lua", buf);
	
	G_LoadLuaScript(NULL, filename);

	G_Printf("-----------------------------------\n");
}
예제 #15
0
//加载lua
void load(char *filename, int *width, int *height) 
{
	lua_State *L = luaL_newstate();
	luaopen_base(L);
	luaopen_io(L);
	luaopen_string(L);
	luaopen_math(L);
	if (luaL_loadfile(L, filename) || lua_pcall(L, 0, 0, 0))
	{
		error(L, "cannot run configuration file: %s", lua_tostring(L, -1));
	}
		
	lua_getglobal(L, "width");
	lua_getglobal(L, "height");
	if (!lua_isnumber(L, -2))	
	{
		error(L, "'width' should be a number\n");
	}
	if (!lua_isnumber(L, -1))
	{
		error(L, "'height' should be a number\n");
	}
	*width = (int)lua_tonumber(L, -2);
	*height = (int)lua_tonumber(L, -1);
	lua_close(L);
}
예제 #16
0
파일: embed3.cpp 프로젝트: KimCM/swig
int main(int argc, char* argv[]) {
  printf("[C++] Welcome to the simple embedded Lua example v3\n");
  printf("[C++] We are in C++\n");
  printf("[C++] opening a Lua state & loading the libraries\n");
  lua_State *L = lua_open();
  luaopen_base(L);
  luaopen_string(L);
  luaopen_math(L);
  printf("[C++] now loading the SWIG wrappered library\n");
  luaopen_example(L);
  printf("[C++] all looks ok\n");
  printf("\n");
  printf("[C++] lets create an Engine and pass a pointer to Lua\n");
  Engine engine;
  /* this code will pass a pointer into lua, but C++ still owns the object
  this is a little tedious, to do, but lets do it
  we need to pass the pointer (obviously), the type name 
  and a flag which states if Lua should delete the pointer once its finished with it
  The type name is a class name string which is registered with SWIG
  (normally, just look in the wrapper file to get this)
  in this case we don't want Lua to delete the pointer so the ownership flag is 0
  */
  push_pointer(L,&engine,"Engine *",0);
  lua_setglobal(L, "pEngine");  // set as global variable

  printf("[C++] now lets load the file 'runme.lua'\n");
  printf("[C++] any lua code in this file will be executed\n");
  if (luaL_loadfile(L, "runme.lua") || 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++] Lets call the Lua function onEvent(e)\n");
  printf("[C++] We will give it different events, as we wish\n");
  printf("[C++] Starting with STARTUP\n");
  Event ev;
  ev.mType = Event::STARTUP;
  call_onEvent(L, ev);
  printf("[C++] ok\n");
  printf("[C++] now we will try MOUSEPRESS,KEYPRESS,MOUSEPRESS\n");
  ev.mType = Event::MOUSEPRESS;
  call_onEvent(L, ev);
  ev.mType = Event::KEYPRESS;
  call_onEvent(L, ev);
  ev.mType = Event::MOUSEPRESS;
  call_onEvent(L, ev);
  printf("[C++] ok\n");
  printf("[C++] Finally we will SHUTDOWN\n");
  ev.mType = Event::SHUTDOWN;
  call_onEvent(L, ev);
  printf("[C++] ok\n");

  printf("\n");
  printf("[C++] all finished, closing the lua state\n");
  lua_close(L);
  return 0;
}
예제 #17
0
bool               P3DPlugLuaRunScript(const char         *FileName,
                                       const P3DPlantModel*PlantModel)
 {
  lua_State                           *State;

  SetCLocale();

  State = lua_open();

  if (State != NULL)
   {
    #if NGP_LUA_VER > 50
    luaL_openlibs(State);
    #else
    luaopen_base(State);
    luaopen_table(State);
    luaopen_io(State);
    luaopen_string(State);
    luaopen_math(State);
    #endif

    P3DPlugLuaRegisterHLI(State);
    P3DPlugLuaRegisterUI(State);
    P3DPlugLuaRegisterFS(State);
    P3DPlugLuaRegisterExportPrefs(State,P3DApp::GetApp()->GetExport3DPrefs());
    P3DPlugLuaRegisterModel(State,"PlantModel",PlantModel);

    lua_register(State,"GetTextureFileName",GetTextureFileName);
    lua_register(State,"GetCurrentLOD",GetCurrentLOD);
    lua_register(State,"GetDerivedFileName",GetDerivedFileName);

    if (luaL_loadfile(State,FileName) || lua_pcall(State,0,0,0))
     {
      if (lua_isstring(State,-1))
       {
        DisplayErrorMessage(wxString(lua_tostring(State,-1),wxConvUTF8));
       }
      else
       {
        DisplayErrorMessage(wxT("Script error: (undefined)"));
       }
     }

    lua_close(State);

    RestoreLocale();

    return(true);
   }
  else
   {
    DisplayErrorMessage(wxT("Unable to initialize Lua environment"));

    RestoreLocale();

    return(false);
   }
 }
예제 #18
0
 int open_string()
 {
     if (L)
     {
         luaopen_string(L);
         return 0;
     }
     return -1;
 }
예제 #19
0
파일: load81.c 프로젝트: cobrajs/load81
void resetProgram(void) {
    char *initscript =
        "keyboard={}; keyboard['pressed']={};"
        "mouse={}; mouse['pressed']={};"
        "sprites={}";

    l81.epoch = 0;
    if (l81.L) lua_close(l81.L);
    l81.L = lua_open();
    luaopen_base(l81.L);
    luaopen_table(l81.L);
    luaopen_string(l81.L);
    luaopen_math(l81.L);
    luaopen_debug(l81.L);
    setNumber("WIDTH",l81.width);
    setNumber("HEIGHT",l81.height);
    luaL_loadbuffer(l81.L,initscript,strlen(initscript),"initscript");
    lua_pcall(l81.L,0,0,0);

    /* Make sure that mouse parameters make sense even before the first
     * mouse event captured by SDL */
    setTableFieldNumber("mouse","x",0);
    setTableFieldNumber("mouse","y",0);
    setTableFieldNumber("mouse","xrel",0);
    setTableFieldNumber("mouse","yrel",0);

    /* Register API */
    lua_pushcfunction(l81.L,fillBinding);
    lua_setglobal(l81.L,"fill");
    lua_pushcfunction(l81.L,filledBinding);
    lua_setglobal(l81.L,"filled");
    lua_pushcfunction(l81.L,rectBinding);
    lua_setglobal(l81.L,"rect");
    lua_pushcfunction(l81.L,ellipseBinding);
    lua_setglobal(l81.L,"ellipse");
    lua_pushcfunction(l81.L,backgroundBinding);
    lua_setglobal(l81.L,"background");
    lua_pushcfunction(l81.L,triangleBinding);
    lua_setglobal(l81.L,"triangle");
    lua_pushcfunction(l81.L,lineBinding);
    lua_setglobal(l81.L,"line");
    lua_pushcfunction(l81.L,textBinding);
    lua_setglobal(l81.L,"text");
    lua_pushcfunction(l81.L,setFPSBinding);
    lua_setglobal(l81.L,"setFPS");
    lua_pushcfunction(l81.L,getpixelBinding);
    lua_setglobal(l81.L,"getpixel");
    lua_pushcfunction(l81.L,spriteBinding);
    lua_setglobal(l81.L,"sprite");
    lua_pushcfunction(l81.L,polygonBinding);
    lua_setglobal(l81.L,"polygon");

    initSpriteEngine(l81.L);

    /* Start with a black screen */
    fillBackground(l81.fb,0,0,0);
}
예제 #20
0
static lua_State* lua_open_betawidget(void)
{
	lua_State* L = lua_open();
	luaopen_base(L);
	luaopen_string(L);
	luaopen_betawidget(L);

	return L;
}
예제 #21
0
void scripting_Init() {
  L = lua_open();
  luaopen_base(L);
  luaopen_table(L);
  luaopen_string(L);
  luaopen_io(L);

  // init_c_interface(L);
}
예제 #22
0
int main()
{
    // Lua 를 초기화 한다.
    lua_State* L = lua_open();

    // Lua 기본 함수들을 로드한다.- print() 사용
    luaopen_base(L);
    // Lua 문자열 함수들을 로드한다.- string 사용
    luaopen_string(L);

    // TestFunc 함수를 Lua 에 등록한다.
    lua_tinker::def(L, "TestFunc", &TestFunc);
    lua_tinker::def(L, "TestFunc2", &TestFunc2);

    // TestClass 클래스를 Lua 에 추가한다.
    lua_tinker::class_add<TestClass>(L, "TestClass");
    // TestClass 의 함수를 등록한다.
    lua_tinker::class_def<TestClass>(L, "TestFunc", &TestClass::TestFunc);
    lua_tinker::class_def<TestClass>(L, "TestFunc2", &TestClass::TestFunc2);

    // TestClass 를 전역 변수로 선언한다.
    TestClass g_test;
    lua_tinker::set(L, "g_test", &g_test);

    // sample3.lua 파일을 로드한다.
    lua_tinker::dofile(L, "sample6.lua");

    // Thread 를 시작한다.
    lua_newthread(L);
    lua_pushstring(L, "ThreadTest");
    lua_gettable(L, LUA_GLOBALSINDEX);

    // Thread 를 시작한다.
    printf("* lua_resume() 호출\n");
    lua_resume(L, 0);

    // Thread 를 다시 시작한다.
    printf("* lua_resume() 호출\n");
    lua_resume(L, 0);

    // Thread 를 다시 시작한다.
    printf("* lua_resume() 호출\n");
    lua_resume(L, 0);

    // Thread 를 다시 시작한다.
    printf("* lua_resume() 호출\n");
    lua_resume(L, 0);

    // Thread 를 다시 시작한다.
    printf("* lua_resume() 호출\n");
    lua_resume(L, 0);

    // 프로그램 종료
    lua_close(L);

    return 0;
}
예제 #23
0
static void open_libs(lua_State *L) 
{
    luaopen_io(L);
    luaopen_base(L);
    luaopen_table(L);
    luaopen_string(L);
    luaopen_math(L);
    // luaopen_loadlib(L);
}
예제 #24
0
void LuaPhysicsSetup::initPhysics()
{
	m_guiHelper->setUpAxis(upaxis);
	const char* prefix[]={"./","./data/","../data/","../../data/","../../../data/","../../../../data/"};
	int numPrefixes = sizeof(prefix)/sizeof(const char*);
	char relativeFileName[1024];
	FILE* f=0;
	int result = 0;

	for (int i=0;!f && i<numPrefixes;i++)
	{
		sprintf(relativeFileName,"%s%s",prefix[i],sLuaFileName);
		f = fopen(relativeFileName,"rb");
	}
	if (f)
	{
		fclose(f);

		lua_State *L = luaL_newstate();

		luaopen_io(L); // provides io.*
		luaopen_base(L);
		luaopen_table(L);
		luaopen_string(L);
		luaopen_math(L);
		//luaopen_package(L);
		luaL_openlibs(L);

		 // make my_function() available to Lua programs
		lua_register(L, "createDefaultDynamicsWorld", gCreateDefaultDynamicsWorld);
		lua_register(L, "deleteDynamicsWorld", gDeleteDynamicsWorld);
		lua_register(L, "createCubeShape", gCreateCubeShape);
		lua_register(L, "createSphereShape", gCreateSphereShape);
		lua_register(L, "loadMultiBodyFromUrdf",gLoadMultiBodyFromUrdf);

		lua_register(L, "createRigidBody", gCreateRigidBody);
		lua_register(L, "setBodyPosition", gSetBodyPosition);
		lua_register(L, "setBodyOrientation", gSetBodyOrientation);



		int s = luaL_loadfile(L, relativeFileName);

		if ( s==0 ) {
		  // execute Lua program
		  s = lua_pcall(L, 0, LUA_MULTRET, 0);
		}

		report_errors(L, s);
		lua_close(L);
	} else
	{
		b3Error("Cannot find Lua file%s\n",sLuaFileName);
	}

}
예제 #25
0
파일: CEGUILua.cpp 프로젝트: B2O/IV-Network
/*************************************************************************
	Constructor (creates Lua state)
*************************************************************************/
LuaScriptModule::LuaScriptModule(lua_State* state) :
    d_ownsState(state == 0),
    d_state(state),
    d_errFuncIndex(LUA_NOREF),
    d_activeErrFuncIndex(LUA_NOREF)
{
    // initialise and create a lua_State if one was not provided
    if (!d_state)
    {
        #if CEGUI_LUA_VER >= 51
            static const luaL_Reg lualibs[] = {
                {"", luaopen_base},
                {LUA_LOADLIBNAME, luaopen_package},
                {LUA_TABLIBNAME, luaopen_table},
                {LUA_IOLIBNAME, luaopen_io},
                {LUA_OSLIBNAME, luaopen_os},
                {LUA_STRLIBNAME, luaopen_string},
                {LUA_MATHLIBNAME, luaopen_math},
            #if defined(DEBUG) || defined (_DEBUG)
                    {LUA_DBLIBNAME, luaopen_debug},
            #endif
                {0, 0}
            };
        #endif /* CEGUI_LUA_VER >= 51 */

        // create a lua state
        d_ownsState = true;
#if LUA_VERSION_NUM > 501
        d_state = luaL_newstate();
#else
        d_state = lua_open();
#endif

        // init all standard libraries
        #if CEGUI_LUA_VER >= 51
                const luaL_Reg *lib = lualibs;
                for (; lib->func; lib++)
                {
                    lua_pushcfunction(d_state, lib->func);
                    lua_pushstring(d_state, lib->name);
                    lua_call(d_state, 1, 0);
                }
        #else /* CEGUI_LUA_VER >= 51 */
            luaopen_base(d_state);
            luaopen_io(d_state);
            luaopen_string(d_state);
            luaopen_table(d_state);
            luaopen_math(d_state);
            #if defined(DEBUG) || defined (_DEBUG)
                luaopen_debug(d_state);
            #endif
        #endif /* CEGUI_LUA_VER >= 51 */
    }

    setModuleIdentifierString();
}
예제 #26
0
LuaInterfaceBase::LuaInterfaceBase(): lua(kaguya::NoLoadLib())
{
    luaopen_base(lua.state());
    luaopen_package(lua.state());
    luaopen_string(lua.state());
    luaopen_table(lua.state());
    luaopen_math(lua.state());

    Register(lua);
}
예제 #27
0
파일: lua_tests.c 프로젝트: mambrus/bitfire
static void 
open_std_libs(lua_State *l) 
{
    luaopen_base(l);   lua_settop(l, 0); 
    luaopen_table(l);  lua_settop(l, 0); 
    luaopen_io(l);     lua_settop(l, 0); 
    luaopen_string(l); lua_settop(l, 0); 
    luaopen_debug(l);  lua_settop(l, 0); 
    luaopen_math(l);   lua_settop(l, 0); 
}
예제 #28
0
LuaState::LuaState()
{
    _state = luaL_newstate();

    luaopen_base(_state);
    //luaopen_io(_state);
    luaopen_math(_state);
    luaopen_string(_state);
    assert(_state);
}
예제 #29
0
파일: luavm_init.c 프로젝트: kotan-kn/pdvms
/*
void luavm_regs(void*vm)
{
	int gc(lua_State*vm)
	{
		return 0;
	}
	int ts(lua_State*vm)
	{
		lua_pushstring(L,"pd");
		return 1;
	}
	lua_newtable(vm);
	int methods=lua_gettop(vm);
	
	lua_newtable(vm,"pd");
	int metatable=lua_gettop(vm);

	lua_pushstring(vm,"pd");
	lua_pushvalue(vm,methods);
	lua_settable(vm,LUA_GLOBALSINDEX);

	lua_pushliteral(vm,"__metatable");
	lua_pushvalue(vm,methods);
	lua_settable(vm,metatable);
	
	lua_pushliteral(vm,"__index");
	lua_pushvalue(vm,methods);
	lua_settable(vm,metatable);
	
	lua_pushliteral(vm,"__tostring");
	lua_pushvalue(vm,methods);
	lua_settable(vm,metatable);
}
*/
void luavm_init(luavm*const ins)
{
	luaopen_base(ins->vm);
	luaopen_table(ins->vm);
	//luaopen_io(ins->vm);
	luaopen_string(ins->vm);
	luaopen_math(ins->vm);
	//luaopen_debug(ins->vm);
	lua_register(ins->vm,"print",print);
	lua_settop(ins->vm,0);
}
예제 #30
0
파일: interp.c 프로젝트: sebcat/birk
interp_t *interp_new(int flags, int ipcfd) {
	interp_t *interp = NULL;
	lua_State *L = NULL;
	static const luaL_Reg ipcfuncs[] = {
		{"ready", bipc_ready},
		{"connect", bipc_connect},
		{NULL, NULL},
	};

	L = luaL_newstate();
	if (L == NULL) {
		return NULL;
	}

	luaopen_base(L);
	luaopen_coroutine(L);
	luaopen_table(L);
	luaopen_string(L);
#if (LUA_VERSION_NUM >= 503)
	luaopen_utf8(L);
#endif
	luaopen_bit32(L);
	luaopen_math(L);
	luaopen_debug(L);
	luaopen_package(L);
	/* not opened: io, os */

	/* create a userdata object that represents the interpreter */
	interp = (interp_t*)lua_newuserdata(L, sizeof(interp_t));
	if (interp == NULL) {
		lua_close(L);
		return NULL;
	}

	memset(interp, 0, sizeof(interp_t));
	interp->ipcfd = ipcfd;
	interp->L = L;

	/* Build a metatable with the methods for our userdata object.
	 * Assign the userdata object to BIRK_IPCNAME */
	luaL_newmetatable(L, BIRK_IPCNAME);
	lua_pushvalue(L, -1);
	lua_setfield(L, -2, "__index");
	luaL_setfuncs(L, ipcfuncs, 0);
	lua_setmetatable(L, -2);
	lua_setglobal(L, BIRK_IPCNAME);

	if ((flags & INTERPF_LOADBIRK) && interp_load(interp, "birk") != BIRK_OK) {
		/* error message is set, caller should check it on return */
		return interp;
	}

	return interp;
}