Пример #1
0
void boot_rpc( void )
{
  lua_State *L = lua_open();
  luaL_openlibs(L);  /* open libraries */
  
  // Set up UART for 8N1 w/ adjustable baud rate
  platform_uart_setup( RPC_UART_ID, RPC_UART_SPEED, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 );
  
  // Start RPC Server
  lua_getglobal( L, "rpc" );
  lua_getfield( L, -1, "server" );
  lua_pushnumber( L, RPC_UART_ID );
  lua_pushnumber( L, RPC_TIMER_ID );
  lua_pcall( L, 2, 0, 0 );
}
Пример #2
0
int main (int argc, char **argv) {
  int status;
  struct Smain s;
  lua_State *L = lua_open();  /* create state */
  if (L == NULL) {
    l_message(argv[0], "cannot create state: not enough memory");
    return EXIT_FAILURE;
  }
  s.argc = argc;
  s.argv = argv;
  status = lua_cpcall(L, &pmain, &s);
  report(L, status);
  lua_close(L);
  return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
}
Пример #3
0
int main_lua(int argc, char* argv[])
{
 lua_State* L;
 struct Smain s;
 int i=doargs(argc,argv);
 argc-=i; argv+=i;
 if (argc<=0) usage("no input files given");
 L=lua_open();
 if (L==NULL) fatal("not enough memory for state");
 s.argc=argc;
 s.argv=argv;
 if (lua_cpcall(L,pmain,&s)!=0) fatal(lua_tostring(L,-1));
 lua_close(L);
 return EXIT_SUCCESS;
}
Пример #4
0
int main ()
{
	Test::Tst_B* b = new Test::Tst_B;         // instance used in Lua code

	lua_State* L = lua_open();
	luaL_openlibs(L);
	tolua_tclass_open(L);

	luaL_dofile(L,"tclass.lua");

	lua_close(L);

	delete b;
	return 0;
}
Пример #5
0
item firstKey(char *filename, char *table) {
    item first;
    lua_State *L = lua_open();
    luaL_openlibs(L);
    luaL_dofile(L, filename);
    lua_getglobal(L, table);
    lua_pushnil(L);
    lua_next(L, -2);
    first.key = (char*)lua_tostring(L, -2);
    if(lua_istable(L, -1))
        first.value = "istable";
    else
        first.value = (char*)lua_tostring(L, -1);
    return first;
}
Пример #6
0
item nextKey(char *filename, char *table, char *key) {
    item next;
    lua_State *L = lua_open();
    luaL_openlibs(L);
    luaL_dofile(L, filename);
    lua_getglobal(L, table);
    lua_pushstring(L, key);
    lua_next(L, -2);
    next.key = (char*)lua_tostring(L, -2);
    if(lua_istable(L, -1))
        next.value = "istable";
    else
        next.value = (char*)lua_tostring(L, -1);
    return next;
}
Пример #7
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;
}
Пример #8
0
int main(int argc, const char * argv[])
{
    if (argc < 2)
    {
        printf("no input path\n");
        exit(1);
    }

    const char* apppath = argv[0];
    char* path = strrchr(argv[0], '/');
    char buff[1024] = {0};
    strncat(buff, apppath, path ? (path - apppath + 1) : 0);
    strcat(buff, "converter.lua");
    
    lua_State* L = lua_open();
    luaL_openlibs(L);
    luaopen_cjson(L);
    luaopen_spinebinary(L);
    luaL_dofile(L, buff);
    
    FILE* file = fopen(argv[1], "r");
    
    if (!file)
    {
        printf("can not open file: %s\n", argv[1]);
        exit(1);
    }
    
    fseek(file, 0, SEEK_END);
    size_t len = ftell(file);
    char* data = (char*)malloc(len);
    fseek(file, 0, SEEK_SET);
    fread(data, 1, len, file);
    fclose(file);
    
    lua_pushcfunction(L, _traceback);
    lua_getglobal(L, "convert");
    luaL_checktype(L, -1, LUA_TFUNCTION);
    lua_pushlstring(L, data, len);
    luaL_gsub(L, argv[1], ".json", ".skel");
    lua_pcall(L, 2, 0, -4);
    
    lua_close(L);

    free(data);
    
    return 0;
}
Пример #9
0
bool RomCommon::LuaManager::Initialise(std::string filename)
{

#ifdef LOGGER
	Logger::getInstance()->Log("LuaManager - Initialising");
#endif

	this->_globalState = lua_open();
	luaL_openlibs(this->_globalState);

#ifdef _DEBUG
	assert(this->_globalState);
#endif

	return true;
}
int main()
{
    lua_State* L = lua_open();
    lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
    luaL_openlibs(L);  /* open libraries */
    lua_gc(L, LUA_GCRESTART, 0);

    push_function_wrapper(L, double_arg);
    lua_setglobal(L, "mah_function");

    luaL_loadfile(L, "main.lua");
    lua_call(L, 0, 0);

    lua_close(L);
    return 0;
}
Пример #11
0
void cLuaState::Create(void)
{
	if (m_LuaState != nullptr)
	{
		LOGWARNING("%s: Trying to create an already-existing LuaState, ignoring.", __FUNCTION__);
		return;
	}
	m_LuaState = lua_open();
	luaL_openlibs(m_LuaState);
	m_IsOwned = true;
	cLuaStateTracker::Add(*this);

	// Add the CanonLuaState value into the Lua state, so that we can get it from anywhere:
	lua_pushlightuserdata(m_LuaState, reinterpret_cast<void *>(this));
	lua_setglobal(m_LuaState, g_CanonLuaStateGlobalName);
}
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);
}
Пример #13
0
int main(int argc, const char** argv)
{
	lua_State* L;
	int z;

	L = lua_open();
	luaL_openlibs(L);

	z = premake_init(L);
	if (z == OKAY) {
		z = premake_execute(L, argc, argv, "src/_premake_main.lua");
	}

	lua_close(L);
	return z;
}
Пример #14
0
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]);
}
Пример #15
0
static int lua_script_start( char const* script )
{
  L = lua_open();
  luaL_openlibs( L );
  register_lua_funcs( L );

  Lt = lua_newthread( L );
  lua_setfield( L, LUA_REGISTRYINDEX, "Lt" );
  if( luaL_loadstring( Lt, script ) != 0 ) {
    script_console_add_line( lua_tostring( Lt, -1 ) );
    lua_script_reset( L );
    return 0;
  }
  lua_sethook(Lt, lua_count_hook, LUA_MASKCOUNT, 1000 );
  return 1;
}
Пример #16
0
static lua_State *lua_init(void)
{
	lua_State *L = lua_open();
	int error = 0;

	if (L) {
		const char *buff = "os.exit = function() freeswitch.consoleLog(\"err\", \"Surely you jest! exiting is a bad plan....\\n\") end";
		lua_gc(L, LUA_GCSTOP, 0);
		luaL_openlibs(L);
		luaopen_freeswitch(L);
		lua_gc(L, LUA_GCRESTART, 0);
		lua_atpanic(L, panic);
		error = luaL_loadbuffer(L, buff, strlen(buff), "line") || docall(L, 0, 0, 0);
	}
	return L;
}
Пример #17
0
LuaManager::LuaManager() : L(NULL) {
    L = lua_open();

    luaL_openlibs(L);

    // initialise built in stuff here

    // fudge in a dungeon module
    lua_getfield(L, LUA_GLOBALSINDEX, "package");
    lua_getfield(L, -1, "loaded");
    lua_newtable(L);
    lua_pushcfunction(L, &dungeon_api_getObjectPosition);
    lua_setfield(L, -2, "getObjectPosition");
    lua_setfield(L, -2, "dungeon");
    lua_pop(L, 2);
}
Пример #18
0
/** Metoda uruchamia skrypt lua, ktory dodaje wszystkie informacje
 *  o spritach. W skrypcie dostepna jest metoda cxx_addSprite
 * @param void
 * @return void
 */
void SpriteManager::loadConfig() {

    lua_State* L = lua_open();
    luaL_openlibs(L);

    // Rejestracja metody ktora jest wywolywna ze skryptu
    lua_register( L, "cxx_addSprite", SpriteManager::addSprite );

    //Wolanie skryptu
    if ( luaL_dofile( L, "data/sprite_config.lua" ) != 0 ) {
        gCritical(lua_tostring( L, -1 ));
        throw("SpriteManager::loadConfig");
    }

    lua_close(L);
}
Пример #19
0
int main ( int argc, char *argv[] )
{
	/* 初始化 Lua */
	L = lua_open();
	/*载入LUA库 */
	luaL_openlibs(L);
	/* 运行LUA脚本 */
// 	luaL_dofile(L, "test.lua");

	luaL_dofile(L, "test.lua");

// 	CallLua();

	lua_close(L);
	return 0;
}
Пример #20
0
GMLUA_DOUBLE_API newState()
{
	luaFile* f = new luaFile();

	f->lua = lua_open();

	if (!f->lua)
	{
		delete f;
		return 0;
	}

	luaL_openlibs(f->lua);

	return (double)(size_t)f;
}
Пример #21
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" );
}
Пример #22
0
void LuaScript::OpenScript(const std::string &script){
    //If the new script name is valid, open it
    if (script != ""){
        //Close currently open script if one is open
        Close();
        mFile = script;
        mL = lua_open();
        luaL_openlibs(mL);
        AddLoader(LuaC::LuaScriptLib::requireLib);
        AddLoader(LuaC::LuaScriptLib::requireScript);
        luaL_dofile(mL, mFile.c_str());
        mOpen = true;
        //Setup function interface
        mFcnInterface = LuaC::FunctionInterface(mL, mFile);
    }
}
Пример #23
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();
}
Пример #24
0
/**
 * Create the lua environnement.
 * @return L
 */
lua_State	*load_lua(void)
{
  lua_State	*L;

  L = lua_open();
  if (L == NULL)
    {
      error("Can't execute lua_open\n");
      return NULL;
    }
  /* open standard libs */
  luaL_openlibs(L);
  init_lua_ui(L);

  return L;
}
Пример #25
0
int lua_sr_init_probe(void)
{
	lua_State *L;
	char *txt;
	sr_lua_load_t *li;
	struct stat sbuf;

	L = lua_open();
	if(L==NULL)
	{
		LM_ERR("cannot open lua\n");
		return -1;
	}
	luaL_openlibs(L);
	lua_sr_openlibs(L);

	/* force loading lua lib now */
	if(luaL_dostring(L, "sr.probe()")!=0)
	{
		txt = (char*)lua_tostring(L, -1);
		LM_ERR("error initializing Lua: %s\n", (txt)?txt:"unknown");
		lua_pop(L, 1);
		lua_close(L);
		return -1;
	}

	/* test if files to be loaded exist */
	if(_sr_lua_load_list != NULL)
	{
		li = _sr_lua_load_list;
		while(li)
		{
			if(stat(li->script, &sbuf)!=0)
			{
				/* file does not exist */
				LM_ERR("cannot find script: %s (wrong path?)\n",
						li->script);
				lua_close(L);
				return -1;
			}
			li = li->next;
		}
	}
	lua_close(L);
	LM_DBG("Lua probe was ok!\n");
	return 0;
}
Пример #26
0
bool LuaStack::init(void)
{
    _state = lua_open();
    luaL_openlibs(_state);
    toluafix_open(_state);

    // Register our version of the global "print" function
    const luaL_reg global_functions [] = {
        {"print", lua_print},
        {"release_print",lua_release_print},
        {nullptr, nullptr}
    };
    luaL_register(_state, "_G", global_functions);

    g_luaType.clear();
    register_all_cocos2dx(_state);
    tolua_opengl_open(_state);
    register_all_cocos2dx_manual(_state);
    register_all_cocos2dx_module_manual(_state);
    register_all_cocos2dx_math_manual(_state);
    register_all_cocos2dx_experimental(_state);
    register_all_cocos2dx_experimental_manual(_state);

    register_glnode_manual(_state);
#if CC_USE_PHYSICS
    register_all_cocos2dx_physics(_state);
    register_all_cocos2dx_physics_manual(_state);
#endif

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
    LuaObjcBridge::luaopen_luaoc(_state);
#endif
    
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    LuaJavaBridge::luaopen_luaj(_state);
#endif
    register_all_cocos2dx_deprecated(_state);
    register_all_cocos2dx_manual_deprecated(_state);
    
    tolua_script_handler_mgr_open(_state);
    register_all_dragonbones(_state);

    // add cocos2dx loader
    addLuaLoader(cocos2dx_lua_loader);

    return true;
}
Пример #27
0
CLuaStateKeeper::CLuaStateKeeper()
{
    // Initialize lua
    m_pLuaState = lua_open();

    if (!m_pLuaState)
        throw Exceptions::CExLua("Could not open lua VM");

    const luaL_Reg *lib = libtable;
    for (; lib->func; lib++)
    {
        lua_pushcfunction(m_pLuaState, lib->func);
        lua_pushstring(m_pLuaState, lib->name);
        lua_call(m_pLuaState, 1, 0);
        lua_settop(m_pLuaState, 0);  // Clear stack
    }
}
Пример #28
0
int lua_script_start( char const* script, int ptp )
{
    lua_script_is_ptp = ptp;
    L = lua_open();
    luaL_openlibs( L );
    register_lua_funcs( L );

    Lt = lua_newthread( L );
    lua_setfield( L, LUA_REGISTRYINDEX, "Lt" );
    if( luaL_loadstring( Lt, script ) != 0 ) {
        lua_script_error(Lt,0);
        return 0;
    }
    lua_sethook(Lt, lua_count_hook, LUA_MASKCOUNT, 1000 );
    lua_script_enable_yield_hook();
    return 1;
}
Пример #29
0
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;
}
Пример #30
0
Файл: m.c Проект: halx99/sherldb
int main() {
    int i;
    const char *file = "my.lua";

    lua_State *L = lua_open();
    luaL_openlibs(L);

    lua_register(L, "c_break", c_break);

    ldb = ldb_new(L, reload);
    luaL_dofile(L, file);

    ldb_free(ldb);
    lua_close(L);

    return 0;
}