Exemplo n.º 1
0
lua_State* LuaWorld::getState()
{
    if(GlobalState==NULL)
    {
        GlobalState = luaL_newstate();
        luaopen_io(GlobalState);
        luaopen_base(GlobalState);
        luaopen_table(GlobalState);
        luaopen_string(GlobalState);
        luaopen_math(GlobalState);
        luaL_openlibs(GlobalState);
    }
    return GlobalState;
}
Exemplo n.º 2
0
Slayer::Slayer()
{
  console->log("Slayer 1.0");

  background = new EntityMgr();
  foreground = new EntityMgr();
  ui         = new EntityMgr();

  lua_state = lua_open();
  luaopen_base(lua_state);
  luaopen_Fuego(lua_state);

  console->log("Lua initialized.");
}
Exemplo n.º 3
0
int LUA::init()
{
  lock();
  printf("LUA\n");
 L = lua_open();
         luaL_checkversion(L);  /* check that interpreter has correct version */
 luaopen_base(L);
         luaL_openlibs(L);  /* open standard libraries */

 hulua::def(L, "_ALERT", LUA::show_error);
 hulua::def(L, "jump", Jump);
 hulua::def(L, "import_xml",import_xml);
 unlock();
}
Exemplo n.º 4
0
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);
}
MyBuffManager::MyBuffManager()
{
	if(m_pSingleton)
		throw "Error";
	else
		m_pSingleton=this;

	lua_State* L = lua_open();
	luaopen_base(L);
	luaL_openlibs(L);
	MyBuffManager::DefineInLua(L);
	lua_tinker::set(L,"BuffManager",this);
	lua_tinker::dofile(L, "./media/lua/Buff/Type.lua");
	lua_close(L);
}
Exemplo n.º 6
0
int main()
{
    // Lua 를 초기화 한다.
    lua_State* L = lua_open();

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

    // Lua 테이블을 생성하고 스택에 푸쉬한다.
    lua_tinker::table haha(L, "haha");

    // haha.value = 1 값을 넣는다.
    haha.set("value", 1);

    // table 내에 table을 만들어 넣는다.
    haha.set("inside", lua_tinker::table(L));

    // haha.inside 의 포인터를 스택위로 복사한다.
    lua_tinker::table inside = haha.get<lua_tinker::table>("inside");

    // inside.value = 2 값을 넣는다.
    inside.set("value", 2);

    // sample4.lua 파일을 로드/실행한다.
    lua_tinker::dofile(L, "sample4.lua");

    // Lua 에서 생성한 haha.test 값을 읽는다.
    const char* test = haha.get<const char*>("test");
    printf("haha.test = %s\n", test);

    // 전역에 등록하지 않고 Lua 스택에 빈 테이블을 생성한다.(지역변수)
    lua_tinker::table temp(L);

    // 빈 테이블.name 에 값을 넣는다.
    temp.set("name", "local table !!");

    // table을 의 인자로 사용하여 print_table 을 호출한다.
    lua_tinker::call<void>(L, "print_table", temp);

    // 함수가 리턴하는 table을 받는다.
    lua_tinker::table ret = lua_tinker::call<lua_tinker::table>(L, "return_table", "give me a table !!");
    printf("ret.name =\t%s\n", ret.get<const char*>("name"));

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

    return 0;
}
void Interpreter::initialize(Renderer *renderer)
{
	interpreter = this;
	mRenderer = renderer;
	L = lua_open();
	printf("opening lua");
	//luaopen_io(L);
	luaopen_base(L);
	luaopen_table(L);
	luaopen_string(L);
	luaopen_math(L);
	//luaopen_loadlib(L);
	printf("registering newIsland");
	lua_register(L, "newIsland", func_newIsland);
	lua_register(L, "clearIslands", func_clearIslands);
}
Exemplo n.º 8
0
LuaScript::LuaScript() 
{
	m_LuaState = lua_open();

	if( m_LuaState )
	{
		// инициализация стандартных библиотечных функции lua
		luaopen_base( m_LuaState );
		luaopen_table( m_LuaState );
		luaopen_string( m_LuaState );
		luaopen_math( m_LuaState );
		luaopen_os( m_LuaState );	
	}
	else
		Log( "Error Initializing Lua" );
}
Exemplo n.º 9
0
void LuaManager::Init()
{
	luaState = lua_open();
	assert(luaState);

	luaopen_base (luaState);
	luaopen_table (luaState);
	luaopen_string (luaState);
	luaopen_math (luaState);
	luaopen_debug (luaState);
	luaL_openlibs(luaState);
	toluafix_open(luaState);
	tolua_attempt_open(luaState);
	SetLuaLoaderFunc(LuaLoader);
	LuaOpenLibName();
}
Exemplo n.º 10
0
// Constructor
_Scripting::_Scripting() :
	Server(nullptr),
	LuaState(nullptr) {

	// Initialize lua object
	LuaState = luaL_newstate();
	luaopen_base(LuaState);
	luaopen_math(LuaState);

	// Set globals
	lua_pushlightuserdata(LuaState, this);
	lua_setglobal(LuaState, "param_scripting");

	// Register C++ functions used by lua
	lua_register(LuaState, "map_change", &MapChangeFunction);
}
Exemplo n.º 11
0
static lua_State *_vms_new( void )
{
	int error = 0;
	lua_State *L = luaL_newstate();
	assert( L );
	luaopen_base( L );
	luaL_openlibs( L );
	/*reg func*/
	lua_register(L, "supex_http", sync_http);
	lua_register(L, "app_lua_get_head_data", app_lua_get_head_data);
	lua_register(L, "app_lua_get_body_data", app_lua_get_body_data);
	lua_register(L, "app_lua_get_path_data", app_lua_get_path_data);
	lua_register(L, "app_lua_get_recv_buf", app_lua_get_recv_buf);
	lua_register(L, "app_lua_get_uri_args", app_lua_get_uri_args);
	lua_register(L, "app_lua_add_send_data", app_lua_add_send_data);
	lua_register(L, "app_lua_mapinit", app_lua_mapinit);
	lua_register(L, "app_lua_convert", app_lua_convert);
	lua_register(L, "app_lua_reverse", app_lua_reverse);
	lua_register(L, "app_lua_ifmatch", app_lua_ifmatch);
	#ifdef OPEN_MDDS
	lua_register(L, "cal_poi_by_line", cal_poi_by_line);
        lua_register(L, "cal_front_road_by_road", cal_front_road_by_road);
	#else
	lua_register(L, "app_lua_lru_cache_set_value", lrucache_setvalue);
	lua_register(L, "app_lua_lru_cache_get_value", lrucache_getvalue);
	lua_register(L, "app_lua_lru_cache_remove_value", lrucache_removevalue);
        lua_register(L, "libkv_cache_set_value", libkv_setvalue);
        lua_register(L, "libkv_cache_get_value", libkv_getvalue);
        lua_register(L, "libkv_cache_delete_key", libkv_deletekey);
	#endif
	/*lua init*/
	{
		extern struct smart_cfg_list g_smart_cfg_list;

		int app_lua_get_serv_name(lua_State *L){
			lua_pushstring( L, g_smart_cfg_list.argv_info.serv_name );
			return 1;
		}
		lua_register(L, "app_lua_get_serv_name", app_lua_get_serv_name);

		error = luaL_dofile(L, "lua/core/init.lua");
		if (error) {
			fprintf(stderr,"%s\n", lua_tostring(L,-1));
			lua_pop(L,1);
			exit(EXIT_FAILURE);
		}
	}
Exemplo n.º 12
0
LuaTcpSocket::LuaTcpSocket(QTcpSocket* socket,boost::function<void ()> disconnect_callback)
: socket_(socket),
  lua_(lua_open()),
  disconnect_callback_(disconnect_callback)
{
  connect(socket_.get(),SIGNAL(readyRead()),SLOT(onReadyRead()));
  connect(socket_.get(),SIGNAL(disconnected()),SLOT(onDisconnect()));

  luaopen_base(lua_);
  luaopen_table(lua_);
  luaopen_string(lua_);
  luaopen_math(lua_);
  luaopen_debug(lua_);
  setSocket(lua_,this);
  lua_register(lua_,"print",&LuaTcpSocket_Print);
  lua_register(lua_,"raw_input",&LuaTcpSocket_RawInput);
}
Exemplo n.º 13
0
initlua(void)
{
	PyObject *m;
	m = Py_InitModule("lua", lua_methods);

	if (!L) {
		L = lua_open();
		luaopen_base(L);
		luaopen_table(L);
		luaopen_io(L);
		luaopen_string(L);
		luaopen_debug(L);
		luaopen_loadlib(L);
		luaopen_python(L);
		lua_settop(L, 0);
	}
}
Exemplo n.º 14
0
int main00000()
{
	
	lua_State* L = lua_open();

	
	luaopen_base(L);
	
	luaopen_string(L);
	lua_tinker::class_add<Base>(L, "Base");
	lua_tinker::class_def<Base>(L, "getvalue", &Base::getvalue);
	lua_tinker::class_add<A>(L, "A");
	lua_tinker::class_inh<A, Base>(L);
	lua_tinker::class_def<A>(L, "getvalue", &A::getvalue);
	lua_tinker::class_mem<A>(L, "value", &A::value);

	lua_tinker::class_add<base>(L, "base");

	lua_tinker::class_def<base>(L, "is_base", &base::is_base);

	
	lua_tinker::class_add<test>(L, "test");

	lua_tinker::class_inh<test, base>(L);

	lua_tinker::class_con<test>(L, lua_tinker::constructor<test,int>);

	lua_tinker::class_def<test>(L, "is_test", &test::is_test);
	lua_tinker::class_def<test>(L, "ret_void", &test::ret_void);
	lua_tinker::class_def<test>(L, "ret_int", &test::ret_int);
	lua_tinker::class_def<test>(L, "ret_mul", &test::ret_mul);
	lua_tinker::class_def<test>(L, "get", &test::get);
	lua_tinker::class_def<test>(L, "set", &test::set);
	lua_tinker::class_mem<test>(L, "_test", &test::_test);
	

	lua_tinker::set(L, "g_test", &g_test);

	lua_tinker::def(L, "createA",&A::create);
	lua_tinker::dofile(L, "sample3.lua");


	lua_close(L);

	return 0;
}
Exemplo n.º 15
0
lua_State *lxc_new_state() 
{
#if defined(LUA_VERSION_NUM) && (LUA_VERSION_NUM >= 501)
	lua_State *L = luaL_newstate();     /* opens Lua */
	luaL_openlibs(L);
#else
	lua_State *L = lua_open();     /* opens Lua */
	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. */
#endif

	luaopen_xchat(L);
	return L;
}
Exemplo n.º 16
0
void
init_lua_state(char *file, char *path, char *cpath){
	L=luaL_newstate();
    luaopen_base(L);
    luaopen_table(L);
    luaopen_string(L);
    luaopen_math(L);
    luaL_openlibs(L);
	int err = luaL_dofile(L, file);
	if (err) {
		fprintf(stderr,"%s\n",lua_tostring(L,-1));
		lua_close(L);
		exit(1);
	}
	setenv("LUA_PATH",path,1);
	setenv("LUA_CPATH",cpath,1);
}
Exemplo n.º 17
0
lua_State* luaInit(char* filename)
{
	lua_State* L = lua_open();
	luaopen_base(L);
	luaopen_string(L);
	luaopen_math(L);

	if (filename && *filename)
	{
		if (luaL_loadfile(L, filename) || lua_pcall(L, 0, 0, 0))
		{
			printf("can not open file: %s", lua_tostring(L, -1));
		}
	}

	return L;
}
Exemplo n.º 18
0
int main(int argc, char* argv[]) {
  if (argc != 2) {
    fprintf(stderr, "lua_curses something.lua\n");
    exit(1);
  }
  
  lua_State* lua= lua_open();
  luaopen_base(lua);
  lua_settop(lua, 0);
  luaopen_string(lua);
  lua_settop(lua, 0);
  // bindings
  lua_pushcfunction(lua, my_addch);
  lua_setglobal(lua, "addch");
  lua_pushcfunction(lua, my_getch);
  lua_setglobal(lua, "getch");
  lua_pushnumber(lua, ERR);
  lua_setglobal(lua, "ERR");
  lua_pushcfunction(lua, my_move);
  lua_setglobal(lua, "move");
  lua_pushcfunction(lua, my_rand);
  lua_setglobal(lua, "rand");
  lua_pushcfunction(lua, my_quit);
  lua_setglobal(lua, "quit");
  lua_pushcfunction(lua, my_start);
  lua_setglobal(lua, "start");

  initscr(); // initialize curses
  cbreak(); // don't buffer user input into lines, but Ctrl-Z and Ctrl-C work as usual
  noecho(); // don't echo user input.
  halfdelay(1); // getch returns ERR if the user takes more than a tenth of a second
  keypad(stdscr, TRUE); // don't ignore function keys F1, F2, etc.
  // TODO: seed the random number generator with the time.

  if (lua_dofile(lua, argv[1])) {
    fprintf(stderr, "lua_curses had a problem opening %s\n", argv[1]);
    endwin();
    exit(1);
  }
  fprintf(stderr, "hello world\n");

  lua_close(lua);
  endwin();
  return 0;
}
Exemplo n.º 19
0
bool 
runLua(const std::string& filename)
{
   GRLUA_DEBUG("Importing scene from " << filename);
   
   // Start a lua interpreter
   lua_State* L = lua_open();
   
   GRLUA_DEBUG("Loading base libraries");
   
   // Load some base library
   luaopen_base(L);
   luaopen_io(L);
   luaopen_string(L);
   luaopen_math(L);
   luaopen_table(L);
   
   GRLUA_DEBUG("Setting up our functions");
   
   // Set up the metatable for gr.node
   luaL_newmetatable(L, "gr.node");
   lua_pushstring(L, "__index");
   lua_pushvalue(L, -2);
   lua_settable(L, -3);
   
   // Load the gr.node methods
   luaL_openlib(L, 0, grlib_node_methods, 0);
   
   // Load the gr functions
   luaL_openlib(L, "gr", grlib_functions, 0);
   
   GRLUA_DEBUG("Parsing the scene");
   
   // Now parse the actual scene
   if (luaL_loadfile(L, filename.c_str()) || lua_pcall(L, 0, 0, 0)) {
      std::cerr << "Error loading " << filename << ": " << lua_tostring(L, -1) << std::endl;
      return false;
   }
   GRLUA_DEBUG("Closing the interpreter");
   
   // Close the interpreter, free up any resources not needed
   lua_close(L);
   
   return true;
}
Exemplo n.º 20
0
int main()
{
	lua_State* L = lua_open();

	luaopen_base(L);

	hulua::set(L, "cpp_int", cpp_int);

	hulua::dofile(L, "sample2.lua");

	int lua_int = hulua::get<int>(L, "lua_int");

	printf("lua_int = %d\n", lua_int);

	lua_close(L);

	return 0;
}
Exemplo n.º 21
0
int main()
{
	lua_State* L = lua_open();

	luaopen_base(L);

	lua_tinker::def(L, "cpp_func", cpp_func);

	lua_tinker::dofile(L, "sample1.lua");

	int result = lua_tinker::call<int>(L, "lua_func", 3, 4);

	printf("lua_func(3,4) = %d\n", result);

	lua_close(L);

	return 0;
}
Exemplo n.º 22
0
int main(int argc,char* argv[])
{
 lua_State *L;
 if (argc<2)
 {
  printf("%s: <filename.lua>\n",argv[0]);
  return 0;
 }
 L=luaL_newstate();
 luaopen_base(L); // load basic libs (eg. print)
 luaopen_example(L);  // load the wrappered module
 if (luaL_loadfile(L,argv[1])==0) // load and run the file
  lua_pcall(L,0,0,0);
 else
  printf("unable to load %s\n",argv[1]);
 lua_close(L);
 return 0;
}
Exemplo n.º 23
0
void ScriptManager::openLuaState() {
	_luaState = lua_open();
	if (!_luaState) {
		throw Common::Exception("Failed to open Lua state");
	}

	luaopen_base(_luaState);
	luaopen_io(_luaState);
	luaopen_math(_luaState);
	luaopen_string(_luaState);
	luaopen_table(_luaState);
	luaopen_loadlib(_luaState);
	luaopen_debug(_luaState);

	tolua_open(_luaState);

	lua_atpanic(_luaState, &ScriptManager::atPanic);
}
Exemplo n.º 24
0
static bool readConfig()
{
    bool ret = false;

    try
    {
        struct msvalue_s config(true);
        struct lua_State* L = luaL_newstate();
        luaopen_base(L);
        luaL_openlibs(L);
        /*TODO::由启动参数指定配置路径*/
        ConnectionServerPassword::getInstance().load(L);
        if (lua_tinker::dofile(L, "ServerConfig//ConnectionServerConfig.lua"))
        {
            aux_readluatable_byname(L, "ConnectionServerConfig", &config);
        }
        else
        {
            throw std::runtime_error("not found ServerConfig//ConnectionServerConfig.lua file");
        }

        map<string, msvalue_s*>& _submapvalue = *config._map;

        selfIP = map_at(_submapvalue, string("selfIP"))->_str;
        portForClient = atoi(map_at(_submapvalue, string("portForClient"))->_str.c_str());
        portForLogicServer = atoi(map_at(_submapvalue, string("portForLogicServer"))->_str.c_str());
        gSelfID = atoi(map_at(_submapvalue, string("id"))->_str.c_str());
        map<string, msvalue_s*>& etcdConfig = *map_at(_submapvalue, string("etcdservers"))->_map;
        for (auto& v : etcdConfig)
        {
            map<string, msvalue_s*>& oneconfig = *((v.second)->_map);
            etcdServers.push_back(std::make_tuple(map_at(oneconfig, string("ip"))->_str, atoi(map_at(oneconfig, string("port"))->_str.c_str())));
        }
        lua_close(L);
        L = nullptr;
        ret = true;
    }
    catch (const std::exception& e)
    {
        errorExit(e.what());
    }

    return ret;
}
Exemplo n.º 25
0
static lua_State *filtro_abrir_lua(modulo_t *modulo, const char *ruta) {
  dato_filtro_t * dato = (dato_filtro_t*)modulo->m_dato;
  lua_State *l;
  static const struct luaL_reg arraylib [] = {
    {"set", filtro_gestos_setarray},
    {"get", filtro_gestos_getarray},
    {"size", filtro_gestos_getsize},
    {"copiar", filtro_gestos_copiar},
    {"crear_copia", filtro_gestos_crear_copia},
    {"difuminar", filtro_gestos_difuminar},
    {"centrar", filtro_gestos_centrar},
    {"rotar", filtro_gestos_rotar},
    {"centrar2", filtro_gestos_centrar2},
    {"buscar_limites", filtro_gestos_buscar_limites},
    {"clean", filtro_gestos_clean},
    {"make_up", filtro_gestos_make_up},
    {"on_border", filtro_gestos_on_border},
    {"borrar_bounds", filtro_gestos_borrar_bounds},
    {NULL, NULL}
  };

  static const struct luaL_reg arrayparam [] = {
    {"get_colores", filtro_gestos_get_colores},
    {NULL, NULL}
  };

  dato->m_lua = lua_open();
  l = dato->m_lua;
  luaL_openlib(l, "imagen", arraylib, 0);
  luaL_openlib(l, "parametros", arrayparam, 0);

  luaopen_base(l);
  luaopen_table(l);
  luaopen_io(l);
  luaopen_string(l);
  luaopen_math(l);
  luaopen_loadlib(l);    

  luaL_loadfile(l, ruta);
  lua_pcall(l, 0, 0, 0);

  return l;
}
Exemplo n.º 26
0
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;
}
Exemplo n.º 27
0
void CLuaMain::InitVM ( void )
{
    assert( !m_luaVM );

    // Create a new VM
    m_luaVM = lua_open ();
    m_pLuaManager->OnLuaMainOpenVM( this, m_luaVM );

    // Set the instruction count hook
    lua_sethook ( m_luaVM, InstructionCountHook, LUA_MASKCOUNT, HOOK_INSTRUCTION_COUNT );

    // Load LUA libraries
    luaopen_base ( m_luaVM );
    luaopen_math ( m_luaVM );
    luaopen_string ( m_luaVM );
    luaopen_table ( m_luaVM );
    luaopen_debug ( m_luaVM );
    luaopen_utf8 ( m_luaVM );

    // Initialize security restrictions. Very important to prevent lua trojans and viruses!
    InitSecurity ();

    // Registering C functions
    CLuaCFunctions::RegisterFunctionsWithVM ( m_luaVM );

    // Create class metatables
    InitClasses ( m_luaVM );

    // Oli: Don't forget to add new ones to CLuaManager::LoadCFunctions. Thanks!

    // create global vars
    lua_pushelement ( m_luaVM, g_pGame->GetMapManager()->GetRootElement() );
    lua_setglobal ( m_luaVM, "root" );

    lua_pushresource ( m_luaVM, m_pResource );
    lua_setglobal ( m_luaVM, "resource" );

    lua_pushelement ( m_luaVM, m_pResource->GetResourceRootElement () );
    lua_setglobal ( m_luaVM, "resourceRoot" );

    // Load pre-loaded lua code
    LoadScript ( szPreloadedScript );
}
Exemplo n.º 28
0
//---------------------------------------------------------------------------//
// Init
//
//---------------------------------------------------------------------------//
bool CLuaFile::Init(const char *pszFile)
{
    End();
    BorraVars();

    m_pLuaState = lua_open();
    if (m_pLuaState)
    {
        m_bOk = true;
        luaopen_base   (m_pLuaState);
        luaopen_table  (m_pLuaState);
        luaopen_string (m_pLuaState);
        luaopen_math   (m_pLuaState);
        luaopen_os     (m_pLuaState);

        // Registrar las funiones y procesar el fichero
#define ITEM(funcname,func) lua_register(m_pLuaState, funcname, func);
#include "EnumFuncionesLua.h"
#undef ITEM
        char pBuffer[MAX_PATH];
        GetCurrentDirectory(MAX_PATH,pBuffer);
        strcat_s(pBuffer, "%s\\demo.lua");
        if (luaL_loadfile(m_pLuaState, pBuffer) == 0)
        {
            if (lua_pcall(m_pLuaState, 0, 0, 0) == 0)
            {
            }
            else
            {
                GLOG(("ERR: Error procesando el fichero LUA '%s'", pszFile));
                End();
            }
        }
        else
        {
            GLOG(("ERR: Can't load LUA file\n"));
            End();
        }
    }

    return (IsOk());
}
Exemplo n.º 29
0
CLuaBridge::CLuaBridge(void) : m_pLuaContext(NULL)
{
	m_pLuaContext = lua_open();

	if (m_pLuaContext != NULL)
	{
		lua_pushcclosure(m_pLuaContext, LuaDebugMessage, 0);
		lua_setglobal(m_pLuaContext, "trace");

		lua_atpanic(m_pLuaContext, (lua_CFunction)HandleLuaAsssert);

		luaopen_io(m_pLuaContext);
		luaopen_math(m_pLuaContext);
		luaopen_base(m_pLuaContext);
		luaopen_loadlib(m_pLuaContext);
		luaopen_table(m_pLuaContext);
		luaopen_string(m_pLuaContext);
		luaopen_debug(m_pLuaContext);		
	}
}
Exemplo n.º 30
0
int main()
{
	// Lua ?? ???? ???.
	lua_State* L = lua_open();

	// Lua ?? ??????? ?¦Å????.- print() ???
	luaopen_base(L);
	// Lua ????? ??????? ?¦Å????.- string ???
	luaopen_string(L);

	// base ??????? Lua ?? ??????.
	lua_tinker::class_add<base>(L, "base");
	// base ?? ????? ??????.
	lua_tinker::class_def<base>(L, "is_base", &base::is_base);

	// test ??????? Lua ?? ??????.
	lua_tinker::class_add<test>(L, "test");
	// test ?? base ?? ??? ??????? ??????.
	lua_tinker::class_inh<test, base>(L);
	// test ????? ??????? ??????.
	lua_tinker::class_con<test>(L, lua_tinker::constructor<test,int>);
	// test ?? ??????? ??????.
	lua_tinker::class_def<test>(L, "is_test", &test::is_test);
	lua_tinker::class_def<test>(L, "ret_void", &test::ret_void);
	lua_tinker::class_def<test>(L, "ret_int", &test::ret_int);
	lua_tinker::class_def<test>(L, "ret_mul", &test::ret_mul);
	lua_tinker::class_def<test>(L, "get", &test::get);
	lua_tinker::class_def<test>(L, "set", &test::set);
	lua_tinker::class_mem<test>(L, "_test", &test::_test);
	
	// Lua ???? ????? g_test ?? ??????? ??????.
	lua_tinker::set(L, "g_test", &g_test);

	// sample3.lua ?????? ?¦Å?/???????.
	lua_tinker::dofile(L, "sample3.lua");

	// ???¦Á?? ????
	lua_close(L);

	return 0;
}