Exemplo n.º 1
0
/*
 * Funkce volaná ze skriptu
 */
LUA_FUNC createBitmap(lua_State* L)
{
    int width, height;
    if (bmp)
    {
        LUA_ERROR("bitmap is already created");
    }

    /* Kontrola počtu parametrů */
    NUMBER_OF_PARAMETERS(2);
    /* Kontrola typu parametrů */
    NUMBERP(1);
    NUMBERP(2);
    width = lua_tointeger(L, 1);
    height = lua_tointeger(L, 2);
    /* Kontrola hodnot parametrů */
    CHECK_RANGE(width, 0, MAX_BITMAP_WIDTH, "bitmap width is out of range");
    CHECK_RANGE(height, 0, MAX_BITMAP_HEIGHT, "bitmap height is out of range");
    /* Vše v pořádku - vytvoříme bitmapu */
    bmp = bitmapCreate(width, height);
    if (bmp == NULL)
    {
        LUA_ERROR("bitmapCreate failed");
    }
    return LUA_OK;
}
Exemplo n.º 2
0
int LunaMessageHandler::connect(lua_State* L)
{
	int nArgs = lua_gettop(L)-1; //element 1 is the table we are in.
	const char* lua_name = luaL_checkstring(L, 2);
	bool lua_inbound = false;
	if(nArgs >= 2)
		lua_inbound = lua_toboolean(L, 3);
	lua_inbound = lua_toboolean(L, 3);

	std::map<const char *, LLMessageTemplate*>::iterator template_iter;
	const char* message_name = LLMessageStringTable::getInstance()->getString(lua_name);
	template_iter = gMessageSystem->mMessageTemplates.find( message_name );
	if(template_iter == gMessageSystem->mMessageTemplates.end())
	{
		LUA_ERROR(llformat("Don't know how to handle a '%s' message", message_name));
		return 0;
	}
	mMessageTemplate = template_iter->second;
	if(lua_inbound)
	{
		mMessageConnection = gMessageSystem->addHandlerFuncFast(message_name, boost::bind(&LunaMessageHandler::slot_func,this,_1));
	}
	else
	{
		LUA_ERROR("inbound is not implemented yet");
	}
	return 0;
}
Exemplo n.º 3
0
/*
 * Funkce volaná ze skriptu
 */
LUA_FUNC saveBitmap(lua_State* L)
{
    if (bmp == NULL)
    {
        LUA_ERROR("bitmap does not exist");
    }
    /* Kontrola počtu parametrů */
    NUMBER_OF_PARAMETERS(1);
    /* Kontrola typu parametrů */
    STRINGP(1);
    if (!bitmapSave(bmp, lua_tostring(L, 1)))
        LUA_ERROR("save bitmap to file failed");
    return LUA_OK;
}
Exemplo n.º 4
0
void LLLuaEngine::console(const std::string & s)
{
	if(luaL_dostring(mState,s.c_str()))
	{
		LUA_ERROR("console" << getError());
	}
}
Exemplo n.º 5
0
void LLLuaEngine::doString(const std::string& s)
{
	if(luaL_dostring(mState,s.c_str()))
	{
		LUA_ERROR("FAILED to run string [" << s << "] reason: " << getError());
	}
}
Exemplo n.º 6
0
/*
 * Funkce volaná ze skriptu
 */
LUA_FUNC putpixel(lua_State* L)
{
    int i, x, y, r, g, b;
    if (bmp == NULL)
    {
        LUA_ERROR("bitmap does not exist");
    }
    /* Kontrola počtu parametrů */
    NUMBER_OF_PARAMETERS(5);
    /* Kontrola typu parametrů - 5 číselných hodnot */
    for (i=1; i<=5; i++)
    {
        NUMBERP(i);
    }
    /* Kontrola hodnot parametrů */
    x = lua_tointeger(L, 1);
    y = lua_tointeger(L, 2);
    r = lua_tointeger(L, 3);
    g = lua_tointeger(L, 4);
    b = lua_tointeger(L, 5);
    CHECK_RANGE(x, 0, bmp->width-1, "x coordinate is out of range");
    CHECK_RANGE(y, 0, bmp->height-1, "y coordinate is out of range");
#if defined(CHECK_COLOR_COMPONENTS)
    CHECK_RANGE(r, 0, 255, "red color component outside 0-255");
    CHECK_RANGE(g, 0, 255, "green color component outside 0-255");
    CHECK_RANGE(b, 0, 255, "blue color component outside 0-255");
#endif
    bitmapPutPixel(bmp, x, y, (unsigned char)r, (unsigned char)g, (unsigned char)b);
    return LUA_OK;
}
Exemplo n.º 7
0
/*
 * Funkce volaná ze skriptu
 */
LUA_FUNC clearBitmap(lua_State* L)
{
    /* Kontrola počtu parametrů */
    NUMBER_OF_PARAMETERS(0);
    if (bmp == NULL)
    {
        LUA_ERROR("bitmap does not exist");
    }
    bitmapClear(bmp);
    return LUA_OK;
}
Exemplo n.º 8
0
void LLLuaEngine::initSingleton()
{
	LL_INFOS("Lua") << "Loading Lua..." << LL_ENDL;
	lua_atpanic(mState, luaOnPanic);

	LL_INFOS("Lua") << "Load standard library with integrated bit and lfs" << LL_ENDL;
	luaL_openlibs(mState);

	//load binding
	bind_print(mState, LuaPrint);
	luna_register(mState, LunaChatCommand); //no message depend

	//logic that happens when idle
	if(LLStartUp::getStartupState() == STATE_STARTED)
	{
		registerBindings();
		LUA_HOOK("OnAgentInit",LUA_ARGS_NONE);
	}

	//hack because im lazy
	std::string version("_SL_VERSION=\"" + gCurrentVersion + "\"");
	if(luaL_dostring(mState,version.c_str()))
	{
		LUA_ERROR(getError());
		return;
	}

	std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_LUA,"_init_.lua");
	if(luaL_dofile(mState, filename.c_str()))
	{
		LUA_ERROR("Failed to load: " << filename << " " << getError());
		return;
	}

	mLoadedFully = true;

	if(mRegisteredBindings)
	{
		LUA_HOOK("OnAgentInit",LUA_ARGS_NONE);
	}
}
Exemplo n.º 9
0
void LLLuaEngine::callHook(const std::string &hook_name, const std::vector< std::string > &args)
{
	if(!LLLuaEngine::instanceExists()) return; //dont hook if lua isnt up and running

	LLLuaEngine &self = instance();

	if(!self.mLoadedFully) return;

	lua_getglobal(self.mState, "callHook");
	lua_pushstring(self.mState, hook_name.c_str());
	for(std::vector< std::string >::const_iterator it = args.begin(); it != args.end(); it++)
	{
		lua_pushstring(self.mState, (*it).c_str());
	}
	if(lua_pcall(self.mState, args.size()+1,1,0))
	{
		LUA_ERROR(self.getError());
	}
	lua_pop(self.mState,1);
}
Exemplo n.º 10
0
static int luaOnPanic(lua_State *L)
{	
	LUA_ERROR("PANIC: " << lua_tostring(L, -1));
	lua_pop(L, -1);
	return 0;
}
Exemplo n.º 11
0
/*virtual*/
void LunaMessageBuilder::printError(const std::string& error)
{
	LUA_ERROR(error);
}
Exemplo n.º 12
0
ERROR_CODE _send_response_handler_lua(struct http_parser_t *http_parser) {
    /* retrieves the connection from the HTTP parser parameters */
    struct connection_t *connection = (struct connection_t *) http_parser->parameters;

    /* retrieves the HTTP connection from the io connection and uses it to retrieve
    the correct (mod Lua) handler to operate around it */
    struct http_connection_t *http_connection = (struct http_connection_t *) ((struct io_connection_t *) connection->lower)->lower;
    struct mod_lua_http_handler_t *mod_lua_http_handler = (struct mod_lua_http_handler_t *) http_connection->http_handler->lower;

    /* allocates space for the result code */
    ERROR_CODE result_code;

    /* acquires the lock on the HTTP connection, this will avoids further
    messages to be processed, no parallel request handling problems */
    http_connection->acquire(http_connection);

    /* in case the Lua state is not started an error must
    have occured so need to return immediately in error */
    if(mod_lua_http_handler->lua_state == NULL) {
        /* writes the error to the connection and then returns
        in error to the caller function */
        _write_error_connection_lua(http_parser, "no Lua state available");
        RAISE_ERROR_M(RUNTIME_EXCEPTION_ERROR_CODE, (unsigned char *) "Problem accessing Lua state");
    }

    /* registers the current connection in Lua */
    lua_pushlightuserdata(mod_lua_http_handler->lua_state, (void *) http_parser);
    lua_setglobal(mod_lua_http_handler->lua_state, "connection");

    /* registers the write connection function in Lua */
    lua_register(mod_lua_http_handler->lua_state, "write_connection", _lua_write_connection);

    /* runs the script in case the current file is considered to be
    dirty, this is the case for the loading of the module and reloading*/
    if(mod_lua_http_handler->file_dirty) { result_code = luaL_dofile(mod_lua_http_handler->lua_state, mod_lua_http_handler->file_path); mod_lua_http_handler->file_dirty = 0; }
    else { result_code = 0; }

    /* in case there was an error in Lua */
    if(LUA_ERROR(result_code)) {
        /* retrieves the error message and then writes it to the connection
        so that the end user may be able to respond to it */
        char *error_message = (char *) lua_tostring(mod_lua_http_handler->lua_state, -1);
        _write_error_connection_lua(http_parser, error_message);

        /* sets the file as dirty (forces reload) and then reloads the curernt
        internal Lua state, virtual machine reset (to avoid corruption) */
        mod_lua_http_handler->file_dirty = 1;
        _reload_lua_state(&mod_lua_http_handler->lua_state);

        /* prints a warning message, closes the Lua interpreter and then
        raises the error to the upper levels */
        V_WARNING_F("There was a problem executing: %s\n", mod_lua_http_handler->file_path);
        RAISE_ERROR_M(RUNTIME_EXCEPTION_ERROR_CODE, (unsigned char *) "Problem executing script file");
    }

    /* retrieves the field reference to the handle method that symbol
    to call the function (in protected mode) and retrieves the result */
    lua_getfield(mod_lua_http_handler->lua_state, LUA_GLOBALSINDEX, "handle");
    result_code = lua_pcall(mod_lua_http_handler->lua_state, 0, 0, 0);

    /* in case there was an error in Lua */
    if(LUA_ERROR(result_code)) {
        /* retrieves the error message and then writes it to the connection
        so that the end user may be able to respond to it */
        char *error_message = (char *) lua_tostring(mod_lua_http_handler->lua_state, -1);
        _write_error_connection_lua(http_parser, error_message);

        /* sets the file reference as dirty, this will force the script file
        to be reload on next request */
        mod_lua_http_handler->file_dirty = 1;

        /* prints a warning message, closes the Lua interpreter and then
        raises the error to the upper levels */
        V_WARNING_F("There was a problem running call on file: %s\n", mod_lua_http_handler->file_path);
        RAISE_ERROR_M(RUNTIME_EXCEPTION_ERROR_CODE, (unsigned char *) "Problem calling the handle method");
    }

    /* raise no error */
    RAISE_NO_ERROR;
}