Exemple #1
0
static int luaB_loadstring (lua_State *L) {
  size_t l;
  const char *s = luaL_checklstring(L, 1, &l);
  const char *chunkname = luaL_optstring(L, 2, s);
  return load_aux(L, luaL_loadbuffer(L, s, l, chunkname));
}
Exemple #2
0
static int luasrc_ConVar (lua_State *L) {
  ConVar *pConVar = new ConVar(luaL_checkstring(L, 1), luaL_checkstring(L, 2), luaL_optint(L, 3, 0), luaL_optstring(L, 4, 0), luaL_optboolean(L, 5, 0), luaL_optnumber(L, 6, 0.0), luaL_optboolean(L, 7, 0), luaL_optnumber(L, 8, 0));
  cvar->RegisterConCommand(pConVar);
  lua_pushconvar(L, pConVar);
  return 1;
}
Exemple #3
0
static int str_split (lua_State *L) {
    size_t l;
    size_t i;
    int n;
    char *q, *p;
    int mult = 0;
    const char *s = luaL_checklstring(L, 1, &l);
    const char *joiner = luaL_optstring(L, 2, " +");
    lua_newtable(L);
    if (l == 0) {
        lua_pushvalue(L,1);
        lua_rawseti(L,-2,1);
        return 1;
    }
    p = malloc(l+1);
    if (p==NULL) {
        fprintf(stderr, "fatal: memory exhausted (malloc of %u bytes).\n",(int)(l+1));
        exit(EXIT_FAILURE);
    }
    strcpy(p,s);
    n = 1;
    q = p;

    if (*joiner == 0) {
        for (i=0; i<l; i++) {
            lua_pushlstring(L,q,1);
            q++;
            lua_rawseti(L,-2,n);
            n++;
        }
        return 1;
    }
    if (*(joiner+1) == '+') {
        mult = 1;
        while(*p==*joiner) {
            p++;
            l--;
        }
        q = p;
    }
    for (i=0; i<l; i++) {
        if (*(p+i)==*joiner) {
            *(p+i) = 0;
            lua_pushlstring(L,q,((p+i)-q));
            lua_rawseti(L,-2,n);
            n++;
            if (mult) {
                while(*(p+i+1)==*joiner) {
                    i++;
                }
            }
            q = p+i+1;
        }
    }
    if (mult && q==(p+l)) {
        return 1;
    }
    if(q<=(p+l)) {
        lua_pushlstring(L,q,strlen(q));
        lua_rawseti(L,-2,n);
    }
    return 1;
}
Exemple #4
0
/** Implement the Lua function GetCurrentConfiguration().
 * 
 * Discover some details about the service's configuration as 
 * known to the \ref ssSCM and report them to the debug trace
 * while building a table from them to return.
 * 
 * \param L Lua state context for the function.
 * \returns The number of values on the Lua stack to be returned
 * to the Lua caller.
 */
static int dbgGetCurrentConfiguration(lua_State *L)
{
    SC_HANDLE schService;
    SC_HANDLE schManager;
    LPQUERY_SERVICE_CONFIG lpqscBuf;
    LPSERVICE_DESCRIPTION lpqscBuf2;
    DWORD dwBytesNeeded;
    const char *name;

    name = luaL_optstring(L, 1, ServiceName);
    SvcDebugTraceStr("Get service configuration for %s:\n", name);
    
    // Open a handle to the service. 
    schManager = OpenSCManagerA(NULL, NULL, (0
	    |GENERIC_READ
	    |SC_MANAGER_CONNECT
	    |SC_MANAGER_CREATE_SERVICE
	    |SC_MANAGER_ENUMERATE_SERVICE
    ));
    if (schManager == NULL)
	return luaL_error(L, "OpenSCManager failed (%d)", GetLastError());
    schService = OpenServiceA(schManager, // SCManager database 
	    name, // name of service 
	    SERVICE_QUERY_CONFIG); // need QUERY access 
    if (schService == NULL) {
	CloseServiceHandle(schManager);
	return luaL_error(L, "OpenService failed (%d)", GetLastError());
    }

    // Allocate buffers for the configuration information.
    lpqscBuf = (LPQUERY_SERVICE_CONFIG) LocalAlloc(
    LPTR, 8192);
    if (lpqscBuf == NULL) {
	CloseServiceHandle(schService);
	CloseServiceHandle(schManager);
	return luaL_error(L, "Can't allocate lpqscBuf");
    }
    lpqscBuf2 = (LPSERVICE_DESCRIPTION) LocalAlloc(
    LPTR, 8192);
    if (lpqscBuf2 == NULL) {
	LocalFree(lpqscBuf);
	CloseServiceHandle(schService);
	CloseServiceHandle(schManager);
	return luaL_error(L, "Can't allocate lpqscBuf2");
    }
    
    // Get the configuration information. 
    if (! QueryServiceConfig(
	    schService,
	    lpqscBuf,
	    8192,
	    &dwBytesNeeded)) {
	LocalFree(lpqscBuf);
	LocalFree(lpqscBuf2);
	CloseServiceHandle(schService);
	CloseServiceHandle(schManager);
	return luaL_error(L, "QueryServiceConfig failed (%d)",
		GetLastError());
    }
    if (! QueryServiceConfig2(
	    schService,
	    SERVICE_CONFIG_DESCRIPTION,
	    (LPBYTE)lpqscBuf2,
	    8192,
	    &dwBytesNeeded)) {
	LocalFree(lpqscBuf);
	LocalFree(lpqscBuf2);
	CloseServiceHandle(schService);
	CloseServiceHandle(schManager);
	return luaL_error(L, "QueryServiceConfig2 failed (%d)",
		GetLastError());
    }

    // Build a table of configuration details, 
    // passing them to the trace log along the way

    lua_newtable(L);
    fieldstr("name", name);
    fieldint("ServiceType", lpqscBuf->dwServiceType);
    fieldint("StartType", lpqscBuf->dwStartType);
    fieldint("ErrorControl", lpqscBuf->dwErrorControl);
    fieldstr("BinaryPathName", lpqscBuf->lpBinaryPathName);
    if (lpqscBuf->lpLoadOrderGroup != NULL)
	fieldstr("LoadOrderGroup", lpqscBuf->lpLoadOrderGroup);
    if (lpqscBuf->dwTagId != 0)
	fieldint("TagId", lpqscBuf->dwTagId);
    if (lpqscBuf->lpDependencies != NULL)
	fieldstr("Dependencies", lpqscBuf->lpDependencies);
    if (lpqscBuf->lpServiceStartName != NULL)
	fieldstr("ServiceStartName", lpqscBuf->lpServiceStartName);
    if (lpqscBuf2->lpDescription != NULL)
	fieldstr("Description", lpqscBuf2->lpDescription);
    
    LocalFree(lpqscBuf);
    LocalFree(lpqscBuf2);
    CloseServiceHandle(schService);
    CloseServiceHandle(schManager);
    return 1;
}
void editor::_editor() {
    //create the window
    keepUserdat=new std::vector<std::pair<unsigned,int64_t>>;
    luaCallback=new std::vector<std::pair<std::string,int64_t>>;
    startLuaConf();
    menu = new Fl_Menu_Bar(0,0,800,24);//Create menubar, items..
    lua_getglobal(Lconf,"generateMenu");
    runLuaFunc(Lconf,0,1);
    {   unsigned menucnt;
        std::vector<Fl_Menu_Item> tmp;
        if(!(menucnt=lua_rawlen(Lconf,-1))) {
            fl_alert("generateMenu must return a table");
            exit(1);
        }
        for(unsigned i=1; i<=menucnt; ++i) {
            lua_rawgeti(Lconf,-1,i);
            unsigned len=lua_rawlen(Lconf,-1);
            if(len) {
                Fl_Menu_Item mi{0};
                lua_rawgeti(Lconf,-1,1);
                char*txt=(char*)luaL_optstring(Lconf,-1,0);
                if(txt)
                    txt=strdup(txt);
                mi.text=txt;
                lua_pop(Lconf,1);
                if(len>=2) {
                    lua_rawgeti(Lconf,-1,2);
                    mi.shortcut_=luaL_optinteger(Lconf,-1,0);
                    lua_pop(Lconf,1);
                } else
                    mi.shortcut_=0;
                int64_t userdat;
                if(len>=4) {
                    lua_rawgeti(Lconf,-1,4);
                    userdat=luaL_optinteger(Lconf,-1,0);
                    lua_pop(Lconf,1);
                } else
                    userdat=0;

                if(len>=3) {
                    lua_rawgeti(Lconf,-1,3);
                    if(lua_type(Lconf,-1)==LUA_TSTRING) {
                        luaCallback->emplace_back(std::make_pair(lua_tostring(Lconf,-1),userdat));
                        mi.callback_=callLuaCB;
                        mi.user_data_=&(*luaCallback)[luaCallback->size()-1];
                    } else if(lua_type(Lconf,-1)==LUA_TNUMBER) {
                        int64_t lcall=lua_tointeger(Lconf,-1);
                        if(lcall>0) {
                            keepUserdat->emplace_back(std::make_pair(lcall-1,userdat));
                            mi.callback_=callCFuncLua;
                            mi.user_data_=&(*keepUserdat)[keepUserdat->size()-1];
                        } else
                            mi.callback_=0;
                    } else {
                        fl_alert("Error invalid type for callback %s",lua_typename(Lconf,lua_type(Lconf,-1)));
                        exit(1);
                    }
                    lua_pop(Lconf,1);
                } else {
                    mi.callback_=0;
                    mi.user_data_=0;
                }
                if(len>=5) {
                    lua_rawgeti(Lconf,-1,5);
                    mi.flags=luaL_optinteger(Lconf,-1,0);
                    lua_pop(Lconf,1);
                } else
                    mi.flags=0;
                tmp.emplace_back(mi);
            } else
                tmp.emplace_back(Fl_Menu_Item{0});
            lua_pop(Lconf,1);
        }
        unsigned cidx=0,lidx=0;
        for(unsigned i=0; i<menucnt; ++i) { //While resizing the vector the addresses may have changed.
            lua_rawgeti(Lconf,-1,i+1);
            unsigned len=lua_rawlen(Lconf,-1);
            if(len>=3) {
                lua_rawgeti(Lconf,-1,3);
                if(lua_type(Lconf,-1)==LUA_TSTRING) {
                    tmp[i].user_data_=&(*luaCallback)[lidx++];
                } else if(lua_type(Lconf,-1)==LUA_TNUMBER) {
                    int64_t lcall=lua_tointeger(Lconf,-1);
                    if(lcall>0)
                        tmp[i].user_data_=&(*keepUserdat)[cidx++];
                }
                lua_pop(Lconf,1);
            }
            lua_pop(Lconf,1);
        }
        lua_pop(Lconf,1);
        menu->copy(tmp.data());
    }
    tile_placer_tile_offset_y=default_tile_placer_tile_offset_y;
    true_color_box_x=default_true_color_box_x;
    true_color_box_y=default_true_color_box_y;
    tile_edit_truecolor_off_x=default_tile_edit_truecolor_off_x;
    tile_edit_truecolor_off_y=default_tile_edit_truecolor_off_y;
    std::fill(tabsHidden,&tabsHidden[shareAmtPj],false);
    {
        the_tabs = new Fl_Tabs(0, 24, 800, 576);
        the_tabs->callback(set_mode_tabs);
        int rx,ry,rw,rh;
        the_tabs->client_area(rx,ry,rw,rh);
        {
            tabsMain.emplace_back(new Fl_Group(rx, ry, rw, rh, "Palette editor"));
            //stuff related to this group should go here
            palBar.addTab(0,true);
            pal_size = new Fl_Hor_Value_Slider(128,384,320,24,"Palette box size");
            pal_size->minimum(1);
            pal_size->maximum(42);
            pal_size->step(1);
            pal_size->value(32);
            pal_size->align(FL_ALIGN_LEFT);
            pal_size->callback(redrawOnlyCB);
            ditherPower = new Fl_Hor_Value_Slider(128,416,320,24,"Dither Power");
            ditherPower->tooltip("A lower value results in more dithering artifacts a higher value results in less artifacts");
            ditherPower->minimum(1);
            ditherPower->maximum(256);
            ditherPower->step(1);
            ditherPower->value(16);
            ditherPower->align(FL_ALIGN_LEFT);
            ditherPower->callback(setSubditherSetting);
            gameSysSel=new Fl_Choice(96, 312, 192, 24);
            gameSysSel->copy(gameSysMenuSel);
            ditherAlgSel=new Fl_Choice(64, 464, 144, 24);
            ditherAlgSel->copy(ditherChoices);
            subSysC=new Fl_Choice(208, 464, 128, 24);
            subSysC->copy(subSysGenesis);
            subSysC->value(0);
            {   Fl_Group *o = new Fl_Group(306, 188, 88, 96);
                {
                    palType[0] = new Fl_Round_Button(306, 188, 64, 32, "Free");
                    palType[0]->type(FL_RADIO_BUTTON);
                    palType[0]->set();
                    palType[0]->callback((Fl_Callback*) setPalType,(void *)0);
                    palType[0]->tooltip(freeDes);
                    palType[1] = new Fl_Round_Button(306, 220, 72, 32, "Locked");
                    palType[1]->type(FL_RADIO_BUTTON);
                    palType[1]->callback((Fl_Callback*) setPalType,(void *)1);
                    palType[1]->tooltip(lockedDes);
                    palType[2] = new Fl_Round_Button(306, 252, 88, 32, "Reserved");
                    palType[2]->type(FL_RADIO_BUTTON);
                    palType[2]->callback((Fl_Callback*) setPalType,(void *)2);
                    palType[2]->tooltip(reservedDes);
                    o->end();
                } // End of buttons
            }//end of group

            lua_getglobal(Lconf,"tabConfig");
            lua_pushinteger(Lconf,pal_edit);
            runLuaFunc(Lconf,1,0);

            tabsMain[pal_edit]->end();
        } // Fl_Group* o
        {   tabsMain.emplace_back(new Fl_Group(rx, ry, rw, rh, "Tile editor"));
            //stuff related to this group should go here
            {   Fl_Group* o = new Fl_Group(0, 0, 800, 567);
                palRTE[0] = new Fl_Round_Button(384, default_palette_bar_offset_y+40, 56, 32, "Row 0");
                palRTE[0]->type(FL_RADIO_BUTTON);
                palRTE[0]->set();
                palRTE[0]->callback((Fl_Callback*) set_tile_row,(void *)0);
                palRTE[1] = new Fl_Round_Button(448, default_palette_bar_offset_y+40, 56, 32, "Row 1");
                palRTE[1]->type(FL_RADIO_BUTTON);
                palRTE[1]->callback((Fl_Callback*) set_tile_row,(void *)1);
                palRTE[2] = new Fl_Round_Button(512, default_palette_bar_offset_y+40, 56, 32, "Row 2");
                palRTE[2]->type(FL_RADIO_BUTTON);
                palRTE[2]->callback((Fl_Callback*) set_tile_row,(void *)2);
                palRTE[3] = new Fl_Round_Button(576, default_palette_bar_offset_y+40, 56, 32, "Row 3");
                palRTE[3]->type(FL_RADIO_BUTTON);
                palRTE[3]->callback((Fl_Callback*) set_tile_row,(void *)3);
                o->end();
            } // Fl_Group* o
            {   Fl_Button *o = new Fl_Button(538, default_palette_bar_offset_y, 104, 32, "Append tile");//these button should be inline with the palette bar
                o->tooltip("This will append a blank tile to the tile buffer in the ram.");
                o->callback(new_tile);
            }
            {   Fl_Button *o = new Fl_Button(656, default_palette_bar_offset_y, 140, 32, "Delete selected tile");
                o->tooltip("This button will delete the currently selected tile");
                o->callback(delete_tile_at_location);
                o->labelsize(12);
            }
            {   Fl_Button *o = new Fl_Button(656, default_palette_bar_offset_y+34,140, 32,"Insert after tile");
                o->callback(insertTileCB);
            }
            palBar.addTab(1);
            rgb_red = new Fl_Hor_Value_Slider(64,default_palette_bar_offset_y+136,128,24,"RGB red");
            rgb_red->minimum(0);
            rgb_red->maximum(255);
            rgb_red->step(1);
            rgb_red->value(0);
            rgb_red->align(FL_ALIGN_LEFT);
            rgb_red->callback(update_truecolor,(void *)0);
            rgb_green = new Fl_Hor_Value_Slider(240,default_palette_bar_offset_y+136,128,24,"Green");
            rgb_green->minimum(0);
            rgb_green->maximum(255);
            rgb_green->step(1);
            rgb_green->value(0);
            rgb_green->align(FL_ALIGN_LEFT);
            rgb_green->callback(update_truecolor,(void *)1);
            rgb_blue = new Fl_Hor_Value_Slider(402,default_palette_bar_offset_y+136,128,24,"Blue");
            rgb_blue->minimum(0);
            rgb_blue->maximum(255);
            rgb_blue->step(1);
            rgb_blue->value(0);
            rgb_blue->align(FL_ALIGN_LEFT);
            rgb_blue->callback(update_truecolor,(void *)2);
            rgb_alpha = new Fl_Hor_Value_Slider(576,default_palette_bar_offset_y+136,128,24,"Alpha");
            rgb_alpha->minimum(0);
            rgb_alpha->maximum(255);
            rgb_alpha->step(1);
            rgb_alpha->value(0);
            rgb_alpha->align(FL_ALIGN_LEFT);
            rgb_alpha->callback(update_truecolor,(void *)3);
            {   Fl_Group *o = new Fl_Group(304, 96, 88, 96);
                {
                    palType[3] = new Fl_Round_Button(304, 96, 64, 32, "Free");
                    palType[3]->type(FL_RADIO_BUTTON);
                    palType[3]->set();
                    palType[3]->callback((Fl_Callback*) setPalType,(void *)0);
                    palType[3]->tooltip(freeDes);
                    palType[4] = new Fl_Round_Button(304, 128, 72, 32, "Locked");
                    palType[4]->type(FL_RADIO_BUTTON);
                    palType[4]->callback((Fl_Callback*) setPalType,(void *)1);
                    palType[4]->tooltip(lockedDes);
                    palType[5] = new Fl_Round_Button(304, 160, 88, 32, "Reserved");
                    palType[5]->type(FL_RADIO_BUTTON);
                    palType[5]->callback((Fl_Callback*) setPalType,(void *)2);
                    palType[5]->tooltip(reservedDes);
                    o->end();
                } // End of buttons
            }//end of group
            {   Fl_Check_Button* o = new Fl_Check_Button(694,default_palette_bar_offset_y+68,100,32,"Show grid?");
                o->callback(set_grid);
                o->tooltip("This button Toggles weather or not you which to see a grid while editing your tiles. A grid can help you see the spacing between each pixel.");
            }
            tile_edit_offset_x=default_tile_edit_offset_x;
            tile_edit_offset_y=default_tile_edit_offset_y;
            tile_size = new Fl_Hor_Value_Slider(448,default_palette_bar_offset_y+72,242,24,"Tile zoom");
            tile_size->tooltip(TooltipZoom);
            tile_size->minimum(1);
            tile_size->maximum(64);
            tile_size->step(1);
            tile_size->value(46);
            tile_size->align(FL_ALIGN_LEFT);
            tile_size->callback(update_offset_tile_edit);
            //now for the tile select slider
            tile_select = new Fl_Hor_Value_Slider(480,default_palette_bar_offset_y+104,312,24,"Tile select");
            tile_select->tooltip("This slider selects which tile that you are editing the first tile is zero");
            tile_select->minimum(0);
            tile_select->maximum(0);
            tile_select->step(1);
            tile_select->align(FL_ALIGN_LEFT);
            tile_select->callback(set_tile_current);
            lua_getglobal(Lconf,"tabConfig");
            lua_pushinteger(Lconf,tile_edit);
            runLuaFunc(Lconf,1,0);
            tabsMain[tile_edit]->end();
        }
        {   tabsMain.emplace_back(new Fl_Group(rx,ry,rw,rh,"Plane mapping/block editor"));
            {   Fl_Group* o = new Fl_Group(tile_place_buttons_x_off, 192, 60, 128);
                palRTE[4] = new Fl_Round_Button(tile_place_buttons_x_off, 192, 60, 28, "Row 0");
                palRTE[4]->type(FL_RADIO_BUTTON);
                palRTE[4]->set();
                palRTE[4]->callback((Fl_Callback*) set_tile_row,(void *)0);
                palRTE[5] = new Fl_Round_Button(tile_place_buttons_x_off, 220, 60, 28, "Row 1");
                palRTE[5]->type(FL_RADIO_BUTTON);
                palRTE[5]->callback((Fl_Callback*) set_tile_row,(void *)1);
                palRTE[6] = new Fl_Round_Button(tile_place_buttons_x_off, 248, 60, 28, "Row 2");
                palRTE[6]->type(FL_RADIO_BUTTON);
                palRTE[6]->callback((Fl_Callback*) set_tile_row,(void *)2);
                palRTE[7] = new Fl_Round_Button(tile_place_buttons_x_off, 276, 60, 28, "Row 3");
                palRTE[7]->type(FL_RADIO_BUTTON);
                palRTE[7]->callback((Fl_Callback*) set_tile_row,(void *)3);
                o->end();
            } // Fl_Group* o


            planeSelect=new Fl_Choice(408,default_palette_bar_offset_y+56,112,24,"Plane selection");
            planeSelect->align(FL_ALIGN_TOP);

            {   Fl_Button *o = new Fl_Button(408, default_palette_bar_offset_y+80,112,24,"Add plane");
                o->callback(addPlaneTilemap);
            }

            {   Fl_Button *o = new Fl_Button(408, default_palette_bar_offset_y+104,112,24,"Remove plane");
                o->callback(removeTilemapsPlane);
            }

            curPlaneName = new Fl_Input(tile_place_buttons_x_off+616,56,168,24,"Plane name");
            curPlaneName->value("0");
            curPlaneName->callback(updateNameTilemaps);

            map_w = new Fl_Int_Input(608,default_palette_bar_offset_y+72,184,24,MapWidthTxt);
            map_w->when(FL_WHEN_ENTER_KEY);
            map_w->value("2");
            map_w->align(FL_ALIGN_LEFT);
            map_w->callback(callback_resize_map);
            map_h = new Fl_Int_Input(608,default_palette_bar_offset_y+104,184,24,MapHeightTxt);
            map_h->when(FL_WHEN_ENTER_KEY);
            map_h->value("2");
            map_h->align(FL_ALIGN_LEFT);
            map_h->callback(callback_resize_map);
            map_amt = new Fl_Int_Input(480,default_palette_bar_offset_y+136,312,24,"Blocks");
            map_amt->value("1");
            map_amt->align(FL_ALIGN_LEFT);
            map_amt->callback(blocksAmtCB);
            map_amt->hide();
            map_x_scroll = new Fl_Scrollbar(default_map_off_x-32, default_map_off_y-32, 800-8-default_map_off_x, 24);
            map_x_scroll->value(0,0,0,0);
            map_x_scroll->type(FL_HORIZONTAL);
            map_x_scroll->tooltip("Use this scroll bar to move around the tile map if you are zoomed in and there is not enough room to display the entire tilemap at once. This scroll bar will move the map left and right.");
            map_x_scroll->callback(update_map_scroll_x);
            map_x_scroll->hide();
            map_x_scroll->linesize(1);
            map_y_scroll = new Fl_Scrollbar(default_map_off_x-32, default_map_off_y, 24, 600-8-default_map_off_y);
            map_y_scroll->value(0,0,0,0);
            //map_x_scroll->type(FL_HORIZONTAL);
            map_y_scroll->tooltip("Use this scroll bar to move around the tile map if you are zoomed in and there is not enough room to display the entire tilemap at once. This scroll bar will move the map up and down.");
            map_y_scroll->callback(update_map_scroll_y);
            map_y_scroll->hide();
            map_y_scroll->linesize(1);
            //now for the tile select slider
            tile_select_2 = new Fl_Hor_Value_Slider(528,default_palette_bar_offset_y+40,264,24,"Tile select");
            tile_select_2->tooltip("This slider allows you to choice which tile you would like to place on the map remember you can both horizontally and vertically flip the tile once placed on the map and select which row the tile uses");
            tile_select_2->minimum(0);
            tile_select_2->maximum(0);
            tile_select_2->step(1);
            tile_select_2->align(FL_ALIGN_TOP_LEFT);
            tile_select_2->callback(set_tile_currentTP);
            totalTiles=new Fl_Box(600,default_palette_bar_offset_y,128,64);
            totalTiles->labelsize(12);
            palBar.addTab(2);
            //buttons for tile settings
            {   Fl_Group *o = new Fl_Group(304, 96, 88, 96);
                {
                    palType[6] = new Fl_Round_Button(304, 90, 64, 32, "Free");
                    palType[6]->type(FL_RADIO_BUTTON);
                    palType[6]->set();
                    palType[6]->callback((Fl_Callback*) setPalType,(void *)0);
                    palType[6]->tooltip(freeDes);
                    palType[7] = new Fl_Round_Button(304, 122, 72, 32, "Locked");
                    palType[7]->type(FL_RADIO_BUTTON);
                    palType[7]->callback((Fl_Callback*) setPalType,(void *)1);
                    palType[7]->tooltip(lockedDes);
                    palType[8] = new Fl_Round_Button(304, 154, 88, 32, "Reserved");
                    palType[8]->type(FL_RADIO_BUTTON);
                    palType[8]->callback((Fl_Callback*) setPalType,(void *)2);
                    palType[8]->tooltip(reservedDes);
                    o->end();
                } // End of buttons
            }//end of group

            hflipCB[0] = new Fl_Check_Button(tile_place_buttons_x_off,304,64,32,"Hflip");
            hflipCB[0]->callback(set_hflipCB,(void*)0);
            hflipCB[0]->tooltip("This sets whether or not the tile is flipped horizontally");
            vflipCB[0] = new Fl_Check_Button(tile_place_buttons_x_off,336,64,32,"Vflip");
            vflipCB[0]->callback(set_vflipCB,(void*)0);
            vflipCB[0]->tooltip("This sets whether or not the tile is flipped vertically");
            prioCB[0] = new Fl_Check_Button(tile_place_buttons_x_off,368,72,32,"Priority");
            prioCB[0]->callback(set_prioCB,(void*)0);
            prioCB[0]->tooltip("If checked tile is high priority");
            {   Fl_Check_Button* o = new Fl_Check_Button(tile_place_buttons_x_off,400,96,32,"Show grid?");
                o->callback(set_grid_placer);
                o->tooltip("This button toggles whether or not a grid is visible over the tile map this will allow you to easily see were each tile is");
            }
            BlocksCBtn = new Fl_Check_Button(tile_place_buttons_x_off,432,96,32,"Blocks?");
            BlocksCBtn->callback(toggleBlocksCB);
            BlocksCBtn->tooltip("Toggles if tile map is treated as blocks");
            {   Fl_Check_Button* o = new Fl_Check_Button(tile_place_buttons_x_off,464,192,32,"Show only selected row");
                o->callback(toggleRowSolo);
                o->tooltip("When checked tiles that do not use the selected row will not be drawn");
            }
            place_tile_size = new Fl_Hor_Value_Slider(tile_place_buttons_x_off,512,168,24,"Tile zoom factor:");
            place_tile_size->minimum(1);
            place_tile_size->maximum(16);
            place_tile_size->step(1);
            place_tile_size->value(12);
            place_tile_size->align(FL_ALIGN_TOP);
            place_tile_size->callback(update_map_size);
            place_tile_size->tooltip(TooltipZoom);

            tmapOffset = new Fl_Int_Input(tile_place_buttons_x_off,552,168,24,"Tile offset");
            tmapOffset->when(FL_WHEN_ENTER_KEY);
            tmapOffset->value("0");
            tmapOffset->align(FL_ALIGN_TOP);
            tmapOffset->callback(setTmapOffsetCB);

            cordDisp[0]=new Fl_Box(tile_place_buttons_x_off,556,128,64);
            cordDisp[0]->labelsize(12);

            lua_getglobal(Lconf,"tabConfig");
            lua_pushinteger(Lconf,tile_place);
            runLuaFunc(Lconf,1,0);
            tabsMain[tile_place]->end();
        }
        {   tabsMain.emplace_back(new Fl_Group(rx,ry,rw,rh,"Chunk editor"));
            useBlocksChunkCBtn=new Fl_Check_Button(8, 48, 152, 24, "Use blocks");
            useBlocksChunkCBtn->callback(useBlocksCB);

            chunkX = new Fl_Scrollbar(DefaultChunkX-32, DefaultChunkY-32, 800-DefaultChunkX+24, 24);
            chunkX->value(0,0,0,0);
            chunkX->type(FL_HORIZONTAL);
            chunkX->callback(scrollChunkX);
            chunkX->hide();

            chunkY = new Fl_Scrollbar(DefaultChunkX-32, DefaultChunkY, 24, 600-8-DefaultChunkY);
            chunkY->value(0,0,0,0);
            chunkY->callback(scrollChunkY);
            chunkY->hide();

            chunk_select = new Fl_Hor_Value_Slider(tile_place_buttons_x_off,88,160,24,"Chunk select");
            chunk_select->minimum(0);
            chunk_select->maximum(0);
            chunk_select->step(1);
            chunk_select->value(0);
            chunk_select->align(FL_ALIGN_TOP);
            chunk_select->callback(currentChunkCB);

            tile_select_3 = new Fl_Hor_Value_Slider(tile_place_buttons_x_off,136,160,24,"Tile select");
            tile_select_3->minimum(0);
            tile_select_3->maximum(0);
            tile_select_3->step(1);
            tile_select_3->align(FL_ALIGN_TOP);
            tile_select_3->callback(selBlockCB);

            hflipCB[1] = new Fl_Check_Button(tile_place_buttons_x_off,160,64,32,"Hflip");
            hflipCB[1]->callback(set_hflipCB,(void*)1);
            vflipCB[1] = new Fl_Check_Button(tile_place_buttons_x_off,192,64,32,"Vflip");
            vflipCB[1]->callback(set_vflipCB,(void*)1);
            prioCB[1] = new Fl_Check_Button(tile_place_buttons_x_off,224,72,32,"Priority");
            prioCB[1]->callback(set_prioCB,(void*)1);

            solidChunkMenu=new Fl_Choice(tile_place_buttons_x_off,256,128,24);
            solidChunkMenu->copy(SolidMenu);

            chunksize[0]=new Fl_Int_Input(tile_place_buttons_x_off,296,128,24,"Width (in tiles)");
            chunksize[0]->when(FL_WHEN_ENTER_KEY);
            chunksize[0]->align(FL_ALIGN_TOP);
            chunksize[0]->callback(resizeChunkCB);
            chunksize[0]->value("16");

            chunksize[1]=new Fl_Int_Input(tile_place_buttons_x_off,336,128,24,"Height (in tiles)");
            chunksize[1]->when(FL_WHEN_ENTER_KEY);
            chunksize[1]->align(FL_ALIGN_TOP);
            chunksize[1]->callback(resizeChunkCB);
            chunksize[1]->value("16");

            planeSelectChunk = new Fl_Hor_Value_Slider(tile_place_buttons_x_off,480,160,24,"Plane select");
            planeSelectChunk->minimum(0);
            planeSelectChunk->maximum(0);
            planeSelectChunk->step(1);
            planeSelectChunk->align(FL_ALIGN_TOP);
            planeSelectChunk->callback(setCurPlaneChunkCB);

            chunk_tile_size = new Fl_Hor_Value_Slider(tile_place_buttons_x_off,520,160,24,"Tile zoom factor:");
            chunk_tile_size->minimum(1);
            chunk_tile_size->maximum(16);
            chunk_tile_size->step(1);
            chunk_tile_size->value(2);
            chunk_tile_size->align(FL_ALIGN_TOP);
            chunk_tile_size->callback(scrollChunkCB);
            chunk_tile_size->tooltip(TooltipZoom);

            cordDisp[1]=new Fl_Box(tile_place_buttons_x_off,556,128,64);
            cordDisp[1]->labelsize(12);

            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off,364, 112, 32, "Append chunk");
                o->callback(appendChunkCB);
            }

            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off,396, 128, 32, "Insert after chunk");
                o->callback(insertChunkCB);
            }
            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off,428, 160, 32, "Delete selected chunk");
                o->callback(delChunkAtCB);
            }
            updateChunkSize();

            lua_getglobal(Lconf,"tabConfig");
            lua_pushinteger(Lconf,chunkEditor);
            runLuaFunc(Lconf,1,0);
            tabsMain[chunkEditor]->end();
        }
        {   tabsMain.emplace_back(new Fl_Group(rx,ry,rw,rh,"Sprites"));
            palBar.addTab(3,false,true,true);
            {   Fl_Group *o = new Fl_Group(tile_place_buttons_x_off+616, 44, 88, 96);
                {
                    palType[9] = new Fl_Round_Button(tile_place_buttons_x_off+616, 44, 64, 24, "Free");
                    palType[9]->type(FL_RADIO_BUTTON);
                    palType[9]->set();
                    palType[9]->callback((Fl_Callback*) setPalType,(void *)0);
                    palType[9]->tooltip(freeDes);
                    palType[10] = new Fl_Round_Button(tile_place_buttons_x_off+616, 68, 72, 24, "Locked");
                    palType[10]->type(FL_RADIO_BUTTON);
                    palType[10]->callback((Fl_Callback*) setPalType,(void *)1);
                    palType[10]->tooltip(lockedDes);
                    palType[11] = new Fl_Round_Button(tile_place_buttons_x_off+616, 92, 88, 24, "Reserved");
                    palType[11]->type(FL_RADIO_BUTTON);
                    palType[11]->callback((Fl_Callback*) setPalType,(void *)2);
                    palType[11]->tooltip(reservedDes);
                    o->end();
                }
            }

            spritegrouptxt = new Fl_Input(tile_place_buttons_x_off+616,128,168,24,"Group name");
            spritegrouptxt->align(FL_ALIGN_TOP);
            spritegrouptxt->value(spriteDefName);
            spritegrouptxt->callback(assignSpritegroupnameCB);

            spritemetatxt = new Fl_Input(tile_place_buttons_x_off+616,168,168,24,"Meta name");
            spritemetatxt->value(spritesName);
            spritemetatxt->callback(assignSpritemetaNameCB);
            spritemetatxt->align(FL_ALIGN_TOP);

            spriteglobaltxt = new Fl_Input(tile_place_buttons_x_off+616,208,168,24,"All meta name");
            spriteglobaltxt->value(defMDesc);
            spriteglobaltxt->callback(assignSpriteAllMetanameCB);
            spriteglobaltxt->align(FL_ALIGN_TOP);


            metaspritesel=new Fl_Hor_Value_Slider(tile_place_buttons_x_off+616,244,168,24,"Meta group select:");
            metaspritesel->step(1);
            metaspritesel->maximum(0);
            metaspritesel->align(FL_ALIGN_TOP);
            metaspritesel->callback(selspriteMeta);
            metaspritesel->labelsize(12);


            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off+616, 274, 96, 28, "Append meta");
                o->callback(appendSpriteCB,(void*)(intptr_t)2);
            }

            spriteselgroup=new Fl_Hor_Value_Slider(tile_place_buttons_x_off,184,168,22,"Sprite group select:");
            spriteselgroup->step(1);
            spriteselgroup->maximum(0);
            spriteselgroup->align(FL_ALIGN_TOP);
            spriteselgroup->callback(selspriteGroup);
            spriteselgroup->labelsize(12);

            spritesel=new Fl_Hor_Value_Slider(tile_place_buttons_x_off,220,168,22,"Sprite select:");
            spritesel->step(1);
            spritesel->maximum(0);
            spritesel->align(FL_ALIGN_TOP);
            spritesel->callback(selSpriteCB);
            spritesel->labelsize(12);

            spritest=new Fl_Hor_Value_Slider(tile_place_buttons_x_off,256,168,22,"Start tile:");
            spritest->step(1);
            spritest->maximum(0);
            spritest->align(FL_ALIGN_TOP);
            spritest->callback(setvalueSpriteCB,0);
            spritest->labelsize(12);

            spriteslat=new Fl_Hor_Value_Slider(tile_place_buttons_x_off,292,168,22,"Mapping tile");
            spriteslat->step(1);
            spriteslat->maximum(0);
            spriteslat->align(FL_ALIGN_TOP);
            spriteslat->callback(setvalueSpriteCB,(void*)4);
            spriteslat->labelsize(12);

            spritesize[0]=new Fl_Hor_Value_Slider(tile_place_buttons_x_off+40,316,128,22,"Width");
            spritesize[0]->step(1);
            spritesize[0]->value(1);
            spritesize[0]->minimum(1);
            spritesize[0]->maximum(4);
            spritesize[0]->align(FL_ALIGN_LEFT);
            spritesize[0]->callback(setvalueSpriteCB,(void*)1);
            spritesize[0]->labelsize(12);

            spritesize[1]=new Fl_Hor_Value_Slider(tile_place_buttons_x_off+40,340,128,22,"Height");
            spritesize[1]->step(1);
            spritesize[1]->value(1);
            spritesize[1]->minimum(1);
            spritesize[1]->maximum(4);
            spritesize[1]->align(FL_ALIGN_LEFT);
            spritesize[1]->callback(setvalueSpriteCB,(void*)2);
            spritesize[1]->labelsize(12);

            spritepalrow=new Fl_Hor_Value_Slider(tile_place_buttons_x_off,376,168,22,"Palette row:");
            spritepalrow->step(1);
            spritepalrow->maximum(3);
            spritepalrow->align(FL_ALIGN_TOP);
            spritepalrow->callback(setvalueSpriteCB,(void*)3);
            spritepalrow->labelsize(12);

            spritezoom=new Fl_Hor_Value_Slider(tile_place_buttons_x_off+38,400,130,22,"Zoom");
            spritezoom->step(1);
            spritezoom->minimum(1);
            spritezoom->value(16);
            spritezoom->maximum(16);
            spritezoom->align(FL_ALIGN_LEFT);
            spritezoom->callback(redrawOnlyCB);
            spritezoom->labelsize(12);

            spritesoff[0] = new Fl_Int_Input(tile_place_buttons_x_off+62,424,106,24,"Offset X:");
            spritesoff[0]->when(FL_WHEN_ENTER_KEY);
            spritesoff[0]->value("0");
            spritesoff[0]->align(FL_ALIGN_LEFT);
            spritesoff[0]->callback(setoffspriteCB,0);

            spritesoff[1] = new Fl_Int_Input(tile_place_buttons_x_off+62,448,106,24,"Offset Y:");
            spritesoff[1]->when(FL_WHEN_ENTER_KEY);
            spritesoff[1]->value("0");
            spritesoff[1]->align(FL_ALIGN_LEFT);
            spritesoff[1]->callback(setoffspriteCB,(void*)1);

            spritehflip = new Fl_Check_Button(tile_place_buttons_x_off,470,48,20,"Hflip");
            spritehflip->callback(spriteHflipCB);
            spritevflip = new Fl_Check_Button(tile_place_buttons_x_off+52,470,48,20,"Vflip");
            spritevflip->callback(spriteVflipCB);
            spriteprio = new Fl_Check_Button(tile_place_buttons_x_off+104,470,56,20,"Priority");
            spriteprio->callback(spritePrioCB);

            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off, 492, 64, 28, "Append");
                o->callback(appendSpriteCB,0);
                o->labelsize(12);
            }
            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off+72, 492, 96, 28, "Append group");
                o->callback(appendSpriteCB,(void*)(intptr_t)1);
                o->labelsize(12);
            }
            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off, 522, 64, 28, "Delete");
                o->callback(delSpriteCB,0);
                o->labelsize(12);
            }
            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off+72, 522, 96, 28, "Delete group");
                o->callback(delSpriteCB,(void*)1);
                o->labelsize(12);
            }
            spritealign[0] = new Fl_Button(tile_place_buttons_x_off, 552, 32, 28, "Left");
            spritealign[0]->labelsize(12);
            spritealign[0]->callback(alignSpriteCB,(void*)0);

            spritealign[1] = new Fl_Button(tile_place_buttons_x_off+34, 552, 40, 28, "Right");
            spritealign[1]->labelsize(12);
            spritealign[1]->callback(alignSpriteCB,(void*)1);

            spritealign[2] = new Fl_Button(tile_place_buttons_x_off+78, 552, 28, 28, "Top");
            spritealign[2]->labelsize(12);
            spritealign[2]->callback(alignSpriteCB,(void*)2);

            spritealign[3] = new Fl_Button(tile_place_buttons_x_off+112, 552, 48, 28, "Bottom");
            spritealign[3]->labelsize(12);
            spritealign[3]->callback(alignSpriteCB,(void*)3);

            {
                Fl_Group *o = new Fl_Group(tile_place_buttons_x_off, 572, 800, 480);
                {
                    Fl_Round_Button*m = new Fl_Round_Button(tile_place_buttons_x_off, 572, 96, 32, "Top corner");
                    m->type(FL_RADIO_BUTTON);
                    m->callback(setDrawSpriteCB,(void *)0);
                    m->set();
                } // Fl_Round_Button* o
                {
                    Fl_Round_Button*m = new Fl_Round_Button(tile_place_buttons_x_off+96, 572, 64, 32, "Center");
                    m->type(FL_RADIO_BUTTON);
                    m->callback(setDrawSpriteCB,(void *)1);
                } // Fl_Round_Button* o
                o->end();
            } // End of buttons

            lua_getglobal(Lconf,"tabConfig");
            lua_pushinteger(Lconf,spriteEditor);
            runLuaFunc(Lconf,1,0);
            tabsMain[spriteEditor]->end();
        }
        {   tabsMain.emplace_back(new Fl_Group(rx,ry,rw,rh,"Level editor"));
            lua_getglobal(Lconf,"tabConfig");
            lua_pushinteger(Lconf,levelEditor);
            runLuaFunc(Lconf,1,0);
            tabsMain[levelEditor]->end();
        }
        {   tabsMain.emplace_back(new Fl_Group(rx,ry,rw,rh,"Settings/projects"));
            projectSelect=new Fl_Hor_Value_Slider(112,56,128,24,"Current project");
            projectSelect->minimum(0);
            projectSelect->maximum(0);
            projectSelect->step(1);
            projectSelect->value(0);
            projectSelect->align(FL_ALIGN_LEFT);
            projectSelect->callback(switchProjectCB);
            {   Fl_Button *o = new Fl_Button(260, 52, 152, 32, "Append blank project");
                o->callback(appendProjectCB);
            }
            {   Fl_Button *o = new Fl_Button(428, 52, 168, 32, "Delete selected project");
                o->callback(deleteProjectCB);
            }
            //IMPORTANT if adding a new tab remember to update these
            sharePrj[0]=new Fl_Check_Button(8,112,112,16,"Share palette");
            sharePrj[0]->callback(shareProjectCB,(void*)pjHavePal);
            sharePrj[1]=new Fl_Check_Button(120,112,96,16,"Share tiles");
            sharePrj[1]->callback(shareProjectCB,(void*)pjHaveTiles);
            sharePrj[2]=new Fl_Check_Button(216,112,120,16,"Share tile map");
            sharePrj[2]->callback(shareProjectCB,(void*)pjHaveMap);
            sharePrj[3]=new Fl_Check_Button(336,112,120,16,"Share chunks");
            sharePrj[3]->callback(shareProjectCB,(void*)pjHaveChunks);
            sharePrj[4]=new Fl_Check_Button(456,112,120,16,"Share sprites");
            sharePrj[4]->callback(shareProjectCB,(void*)pjHaveSprites);
            sharePrj[5]=new Fl_Check_Button(576,112,120,16,"Share level");
            sharePrj[5]->callback(shareProjectCB,(void*)pjHaveLevel);

            havePrj[0]=new Fl_Check_Button(8,88,112,16,"Have palette");
            havePrj[0]->callback(haveCB,(void*)pjHavePal);
            havePrj[1]=new Fl_Check_Button(120,88,96,16,"Have tiles");
            havePrj[1]->callback(haveCB,(void*)pjHaveTiles);
            havePrj[2]=new Fl_Check_Button(232,88,120,16,"Have tile map");
            havePrj[2]->callback(haveCB,(void*)pjHaveMap);
            havePrj[3]=new Fl_Check_Button(344,88,120,16,"Have chunks");
            havePrj[3]->callback(haveCB,(void*)pjHaveChunks);
            havePrj[4]=new Fl_Check_Button(456,88,120,16,"Have sprites");
            havePrj[4]->callback(haveCB,(void*)pjHaveSprites);
            havePrj[5]=new Fl_Check_Button(568,88,120,16,"Have level");
            havePrj[5]->callback(haveCB,(void*)pjHaveLevel);

            shareWith[0]=new Fl_Hor_Value_Slider(8,142,128,24,"Share palette with:");
            shareWith[0]->callback(switchShareCB,(void*)pjHavePal);
            shareWith[1]=new Fl_Hor_Value_Slider(136,142,128,24,"Share tiles with:");
            shareWith[1]->callback(switchShareCB,(void*)pjHaveTiles);
            shareWith[2]=new Fl_Hor_Value_Slider(264,142,128,24,"Share tile map with:");
            shareWith[2]->callback(switchShareCB,(void*)pjHaveMap);
            shareWith[3]=new Fl_Hor_Value_Slider(400,142,128,24,"Share chunks with:");
            shareWith[3]->callback(switchShareCB,(void*)pjHaveChunks);
            shareWith[4]=new Fl_Hor_Value_Slider(536,142,128,24,"Share sprites with:");
            shareWith[4]->callback(switchShareCB,(void*)pjHaveSprites);
            shareWith[5]=new Fl_Hor_Value_Slider(672,142,128,24,"Share level with:");
            shareWith[5]->callback(switchShareCB,(void*)pjHaveLevel);
            for(unsigned x=0; x<shareAmtPj; ++x) {
                havePrj[x]->value(1);
                shareWith[x]->minimum(0);
                shareWith[x]->maximum(0);
                shareWith[x]->step(1);
                shareWith[x]->value(0);
                shareWith[x]->align(FL_ALIGN_TOP);
            }


            TxtBufProject = new Fl_Text_Buffer;
            TxtEditProject = new Fl_Text_Editor(8, 184, 640, 370,"Description/Notes");
            TxtEditProject->buffer(TxtBufProject);
            TxtEditProject->textfont(FL_TIMES);
            TxtBufProject->text(currentProject->Name.c_str());
            lua_getglobal(Lconf,"tabConfig");
            lua_pushinteger(Lconf,settingsTab);
            runLuaFunc(Lconf,1,0);
            tabsMain[settingsTab]->end();
        }
        {   tabsMain.emplace_back(new Fl_Group(rx,ry,rw,rh,"Lua scripting"));
            luaScriptSel=new Fl_Choice(tile_place_buttons_x_off,default_palette_bar_offset_y+8,112,24);
            luaScriptSel->label("Script selection");
            luaScriptSel->align(FL_ALIGN_TOP);
            luaScriptSel->callback(switchCurLuaScript);
            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off+120, default_palette_bar_offset_y,112, 32, "Append script");
                o->callback(appendLuaScript);
            }
            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off+240, default_palette_bar_offset_y,144,32, "Delete selected script");
                o->callback(deleteLuaScript);
            }
            {   Fl_Button *o = new Fl_Button(tile_place_buttons_x_off+392, default_palette_bar_offset_y,48,32, "Run");
                o->callback(runCurLuaScript);
            }
            luaScriptName = new Fl_Input(tile_place_buttons_x_off+448+8,default_palette_bar_offset_y+8,328,24,"Script name");
            luaScriptName->callback(setNameLuaScript);
            luaScriptName->align(FL_ALIGN_TOP);
            luaBufProject = new Fl_Text_Buffer;
            luaEditProject = new Fl_Text_Editor(tile_place_buttons_x_off,default_palette_bar_offset_y+48, 784, 456,"Currently selected Lua script");
            luaEditProject->buffer(luaBufProject);
            luaEditProject->textfont(FL_COURIER);
            luaEditProject->hide();
            lua_getglobal(Lconf,"tabConfig");
            lua_pushinteger(Lconf,luaTab);
            runLuaFunc(Lconf,1,0);
            tabsMain[luaTab]->end();
        }
    }
}
static int luaB_assert (lua_State *L) {
  if (!lua_toboolean(L, 1))
    return luaL_error(L, "%s", luaL_optstring(L, 2, "assertion failed!"));
  return lua_gettop(L);
}
int luatpt_set_property(lua_State* l)
{
	const char *name;
	int r, i, x, y, w, h, t, nx, ny, partsel = 0;
	float f;
	int acount = lua_gettop(l);
	const char* prop = luaL_optstring(l, 1, "");

	CommandInterface::FormatType format;
	int offset = luacon_ci->GetPropertyOffset(prop, format);
	if (offset == -1)
		return luaL_error(l, "Invalid property '%s'", prop);

	if (acount > 2)
	{
		if(!lua_isnumber(l, acount) && lua_isstring(l, acount))
		{
			name = luaL_optstring(l, acount, "none");
			if ((partsel = luacon_ci->GetParticleType(std::string(name))) == -1)
				return luaL_error(l, "Unrecognised element '%s'", name);
		}
	}
	if (lua_isnumber(l, 2))
	{
		if (format == CommandInterface::FormatFloat)
			f = luaL_optnumber(l, 2, 0);
		else
			t = luaL_optint(l, 2, 0);

		if (!strcmp(prop,"type") && (t<0 || t>=PT_NUM || !luacon_sim->elements[t].Enabled))
			return luaL_error(l, "Unrecognised element number '%d'", t);
	}
	else
	{
		name = luaL_checklstring(l, 2, NULL);
		if ((t = luacon_ci->GetParticleType(std::string(name)))==-1)
			return luaL_error(l, "Unrecognised element '%s'", name);
	}
	if (!lua_isnumber(l, 3) || acount >= 6)
	{
		// Got a region
		if (acount < 6)
		{
			i = 0;
			y = 0;
			w = XRES;
			h = YRES;
		}
		else
		{
			i = abs(luaL_checkint(l, 3));
			y = abs(luaL_checkint(l, 4));
			w = abs(luaL_checkint(l, 5));
			h = abs(luaL_checkint(l, 6));
		}
		if (i>=XRES || y>=YRES)
			return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);
		x = i;
		if(x+w > XRES)
			w = XRES-x;
		if(y+h > YRES)
			h = YRES-y;
		Particle * parts = luacon_sim->parts;
		for (i = 0; i < NPART; i++)
		{
			if (parts[i].type)
			{
				nx = (int)(parts[i].x + .5f);
				ny = (int)(parts[i].y + .5f);
				if (nx >= x && nx < x+w && ny >= y && ny < y+h && (!partsel || partsel == parts[i].type))
				{
					if (format == CommandInterface::FormatElement)
						luacon_sim->part_change_type(i, nx, ny, t);
					else if(format == CommandInterface::FormatFloat)
						*((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = f;
					else
						*((int*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = t;
				}
			}
		}
	}
	else
	{
		i = abs(luaL_checkint(l, 3));
		// Got coords or particle index
		if (lua_isnumber(l, 4))
		{
			y = abs(luaL_checkint(l, 4));
			if (i>=XRES || y>=YRES)
				return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);
			r = luacon_sim->pmap[y][i];
			if (!r || (partsel && partsel != (r&0xFF)))
				r = luacon_sim->photons[y][i];
			if (!r || (partsel && partsel != (r&0xFF)))
				return 0;
			i = r>>8;
		}
		if (i < 0 || i >= NPART)
			return luaL_error(l, "Invalid particle ID '%d'", i);
		if (!luacon_sim->parts[i].type)
			return 0;
		if (partsel && partsel != luacon_sim->parts[i].type)
			return 0;

		if (format == CommandInterface::FormatElement)
			luacon_sim->part_change_type(i, luacon_sim->parts[i].x, luacon_sim->parts[i].y, t);
		else if (format == CommandInterface::FormatFloat)
			*((float*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = f;
		else
			*((int*)(((unsigned char*)&luacon_sim->parts[i])+offset)) = t;
	}
Exemple #8
0
static int KeyValues_SaveToFile (lua_State *L) {
  lua_pushboolean(L, luaL_checkkeyvalues(L, 1)->SaveToFile(filesystem, luaL_checkstring(L, 2), luaL_optstring(L, 3, 0)));
  return 1;
}
Exemple #9
0
static int 
lua_basename(lua_State *L)
{
  const char *fname = luaL_checkstring(L, 1);
  const char *suffix = luaL_optstring(L, 2, 0);

#ifdef _WIN32

  int sl;
  const char *p, *s;
  SB sb;
  sbinit(&sb);
  /* Special cases */
  if (fname[0] && fname[1]==':') {
    sbaddn(&sb, fname, 2);
    fname += 2;
    if (fname[0]=='/' || fname[0]=='\\')
      sbadd1(&sb, '/');
    while (fname[0]=='/' || fname[0]=='\\')
      fname += 1;
    if (fname[0]==0)
      return sbpush(L, &sb);
    sb.len = 0;
  }
  /* Position p after last nontrivial slash */
  s = p = fname;
  while (*s) {
    if ((s[0]=='\\' || s[0]=='/') &&
        (s[1] && s[1]!='/' && s[1]!='\\' ) )
      p = s + 1;
    s++;
  }
  /* Copy into buffer */
  while (*p && *p!='/' && *p!='\\')
    sbadd1(&sb, *p++);
  /* Process suffix */
  if (suffix==0 || suffix[0]==0)
    return sbpush(L, &sb);
  if (suffix[0]=='.')
    suffix += 1;
  if (suffix[0]==0)
    return sbpush(L, &sb);
  sl = strlen(suffix);
  if (sb.len > sl) {
    s =  sb.buffer + sb.len - (sl + 1);
    if (s[0]=='.' && _strnicmp(s+1,suffix, sl)==0)
      sb.len = s - sb.buffer;
  }
  return sbpush(L, &sb);
  
#else

  int sl;
  const char *s, *p;
  SB sb;
  sbinit(&sb);
  /* Position p after last nontrivial slash */
  s = p = fname;
  while (*s) {
    if (s[0]=='/' && s[1] && s[1]!='/')
      p = s + 1;
    s++;
  }
  /* Copy into buffer */
  while (*p && *p!='/')
    sbadd1(&sb, *p++);
  /* Process suffix */
  if (suffix==0 || suffix[0]==0)
    return sbpush(L, &sb);
  if (suffix[0]=='.')
    suffix += 1;
  if (suffix[0]==0)
    return sbpush(L, &sb);
  sl = strlen(suffix);
  if (sb.len > sl) {
    s =  sb.buffer + sb.len - (sl + 1);
    if (s[0]=='.' && strncmp(s+1,suffix, sl)==0)
      sb.len = s - sb.buffer;
  }
  return sbpush(L, &sb);

#endif
}
Exemple #10
0
static int api_hexchat_emit_print_attrs(lua_State *L)
{
    hexchat_event_attrs *attrs = *(hexchat_event_attrs **)luaL_checkudata(L, 1, "attrs");
    hexchat_emit_print_attrs(ph, attrs, luaL_checkstring(L, 2), luaL_optstring(L, 3, NULL), luaL_optstring(L, 4, NULL), luaL_optstring(L, 5, NULL), luaL_optstring(L, 6, NULL), luaL_optstring(L, 7, NULL), NULL);
    return 0;
}
Exemple #11
0
static int KeyValues_GetDataType (lua_State *L) {
  lua_pushinteger(L, luaL_checkkeyvalues(L, 1)->GetDataType(luaL_optstring(L, 2, 0)));
  return 1;
}
Exemple #12
0
static int api_hexchat_emit_print(lua_State *L)
{
    hexchat_emit_print(ph, luaL_checkstring(L, 1), luaL_optstring(L, 2, NULL), luaL_optstring(L, 3, NULL), luaL_optstring(L, 4, NULL), luaL_optstring(L, 5, NULL), luaL_optstring(L, 6, NULL), NULL);
    return 0;
}
Exemple #13
0
static int db_getinfo (lua_State *L) {
  lua_Debug ar;
  int arg;
  //add by cuiwei 07.8.30
  int i;
  char aparms[1024] = {0};
  //add end
  lua_State *L1 = getthread(L, &arg);
  const char *options = luaL_optstring(L, arg+2, "flnSu");
  if (lua_isnumber(L, arg+1)) {
    if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
      lua_pushnil(L);  /* level out of range */
      return 1;
    }
  }
  else if (lua_isfunction(L, arg+1)) {
    lua_pushfstring(L, ">%s", options);
    options = lua_tostring(L, -1);
    lua_pushvalue(L, arg+1);
    lua_xmove(L, L1, 1);
  }
  else
    return luaL_argerror(L, arg+1, "function or level expected");
  if (!lua_getinfo(L1, options, &ar))
    return luaL_argerror(L, arg+2, "invalid option");
  lua_createtable(L, 0, 2);
  if (strchr(options, 'S')) {
    settabss(L, "source", ar.source);
    settabss(L, "short_src", ar.short_src);
    settabsi(L, "linedefined", ar.linedefined);
    settabsi(L, "lastlinedefined", ar.lastlinedefined);
    settabss(L, "what", ar.what);
  }
  if (strchr(options, 'l'))
    settabsi(L, "currentline", ar.currentline);
  if (strchr(options, 'u'))
  {
    settabsi(L, "nups", ar.nups);
	//add by cuiwei 07.8.30
	if (ar.what != "C" )
	{
		settabsi(L, "npars", ar.npars);
		settabsi(L, "has3dot", ar.has3dot?1:0);
		for ( i = 1; i <= ar.npars; i++ )
		{
			strcat(aparms, ar.parms[i-1]);
			if ( i != ar.npars || ar.has3dot)
			{
				strcat(aparms, ",");
			}
		}
		if ( ar.has3dot )
		{
			strcat(aparms, "...");
		}	settabss(L, "strparms", aparms);
	}
	//add end
  }
  if (strchr(options, 'n')) {
    settabss(L, "name", ar.name);
    settabss(L, "namewhat", ar.namewhat);
  }
  if (strchr(options, 'L'))
    treatstackoption(L, L1, "activelines");
  if (strchr(options, 'f'))
    treatstackoption(L, L1, "func");
  return 1;  /* return table */
}
int luatpt_error(lua_State* l)
{
	std::string errorMessage = std::string(luaL_optstring(l, 1, "Error text"));
	ErrorMessage::Blocking("Error", errorMessage);
	return 0;
}
Exemple #15
0
/**
 * \brief Implementation of sol.file.open().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::file_api_open(lua_State* l) {

  const std::string& file_name = luaL_checkstring(l, 1);
  const std::string& mode = luaL_optstring(l, 2, "r");

  const bool writing = mode != "r" && mode != "rb";

  // file_name is relative to the data directory, the data archive or the
  // quest write directory.
  // Let's determine the real file name and pass it to io.open().
  std::string real_file_name;
  if (writing) {

    // Writing a file.
    if (FileTools::get_quest_write_dir().empty()) {
      error(l, "Cannot open file in writing: no write directory was specified in quest.dat");
    }

    real_file_name = FileTools::get_full_quest_write_dir() + "/" + file_name;
  }
  else {
    // Reading a file.
    FileTools::DataFileLocation location = FileTools::data_file_get_location(file_name);

    switch (location) {

      case FileTools::LOCATION_NONE:
        // Not found.
        lua_pushnil(l);
        push_string(l, std::string("Cannot find file '") + file_name
            + "' in the quest write directory, in data/, data.solarus or in data.solarus.zip");
        return 2;

      case FileTools::LOCATION_WRITE_DIRECTORY:
        // Found in the quest write directory.
        real_file_name = FileTools::get_full_quest_write_dir() + "/" + file_name;
        break;

      case FileTools::LOCATION_DATA_DIRECTORY:
        // Found in the data directory.
        real_file_name = FileTools::get_quest_path() + "/data/" + file_name;
        break;

      case FileTools::LOCATION_DATA_ARCHIVE:
        {
          // Found in the data archive.
          // To call io.open(), we need a regular file, so let's create
          // a temporary one.
          char* buffer;
          size_t size;
          FileTools::data_file_open_buffer(file_name, &buffer, &size);
          real_file_name = FileTools::create_temporary_file(buffer, size);
          FileTools::data_file_close_buffer(buffer);
          break;
        }
    }
  }

  // Call io.open.
  lua_getfield(l, LUA_REGISTRYINDEX, "io.open");
  push_string(l, real_file_name);
  push_string(l, mode);

  bool called = call_function(l, 2, 2, "io.open");
  if (!called) {
    error(l, "Unexpected error: failed to call io.open()");
  }

  return 2;
}
Exemple #16
0
/*
** Returns a row of data from the query
** Lua Returns:
**   list of results or table of results depending on call
**   nil and error message otherwise.
*/
static int cur_fetch (lua_State *L) {
	ISC_STATUS fetch_stat;
	int i;
	cur_data *cur = getcursor(L,1);
	const char *opts = luaL_optstring (L, 3, "n");
	int num = strchr(opts, 'n') != NULL;
	int alpha = strchr(opts, 'a') != NULL;

	if ((fetch_stat = isc_dsql_fetch(cur->env->status_vector, &cur->stmt, 1, cur->out_sqlda)) == 0) {
		if (lua_istable (L, 2)) {
			/* remove the option string */
			lua_settop(L, 2);

			/* loop through the columns */
			for (i = 0; i < cur->out_sqlda->sqld; i++) {
				push_column(L, i, cur);

				if( num ) {
					lua_pushnumber(L, i+1);
					lua_pushvalue(L, -2);
					lua_settable(L, 2);
				}

				if( alpha ) {
					lua_pushlstring(L, cur->out_sqlda->sqlvar[i].aliasname, cur->out_sqlda->sqlvar[i].aliasname_length);
					lua_pushvalue(L, -2);
					lua_settable(L, 2);
				}

				lua_pop(L, 1);
			}

			/* returning given table */
			return 1;
		} else {
			for (i = 0; i < cur->out_sqlda->sqld; i++)
				push_column(L, i, cur);

			/* returning a list of values */
			return cur->out_sqlda->sqld;
		}
	}

	/* isc_dsql_fetch returns 100 if no more rows remain to be retrieved
	   so this can be ignored */
	if (fetch_stat != 100L)
		return return_db_error(L, cur->env->status_vector);

	/* last row has been fetched, close cursor */
	isc_dsql_free_statement(cur->env->status_vector, &cur->stmt, DSQL_drop);
	if ( CHECK_DB_ERROR(cur->env->status_vector) )
		return return_db_error(L, cur->env->status_vector);

	/* free the cursor data */
	free_cur(cur);

	cur->closed = 1;

	/* remove cursor from lock count */
	--cur->conn->lock;

	/* return sucsess */
	return 0;
}
Exemple #17
0
static int luaB_loadfile(lua_State* L)
{
	const char* fname = luaL_optstring(L, 1, NULL);
	return load_aux(L, luaL_loadfile(L, fname));
}
Exemple #18
0
/*
** Creates and returns a connection object
** Lua Input: source, user, pass
**   source: data source
**   user, pass: data source authentication information
** Lua Returns:
**   connection object if successfull
**   nil and error message otherwise.
*/
static int env_connect (lua_State *L) {
	char *dpb;
	int i;
	static char isc_tpb[] = {	isc_tpb_version3,
								isc_tpb_write		};
	conn_data conn;
	conn_data* res_conn;

	env_data *env = (env_data *) getenvironment (L, 1);
	const char *sourcename = luaL_checkstring (L, 2);
	const char *username = luaL_optstring (L, 3, "");
	const char *password = luaL_optstring (L, 4, "");

	conn.env = env;
	conn.db = 0L;
	conn.transaction = 0L;
	conn.lock = 0;
	conn.autocommit = 0;

	/* Construct a database parameter buffer. */
	dpb = conn.dpb_buffer;
	*dpb++ = isc_dpb_version1;
	*dpb++ = isc_dpb_num_buffers;
	*dpb++ = 1;
	*dpb++ = 90;

	/* add the user name and password */
	*dpb++ = isc_dpb_user_name;
    *dpb++ = (char)strlen(username);
	for(i=0; i<(int)strlen(username); i++)
		*dpb++ = username[i];
	*dpb++ = isc_dpb_password;
    *dpb++ = (char)strlen(password);
	for(i=0; i<(int)strlen(password); i++)
		*dpb++ = password[i];

	/* the length of the dpb */
	conn.dpb_length = (short)(dpb - conn.dpb_buffer);

	/* do the job */
	isc_attach_database(env->status_vector, (short)strlen(sourcename), (char*)sourcename, &conn.db,
						conn.dpb_length,	conn.dpb_buffer);

	/* an error? */
	if ( CHECK_DB_ERROR(conn.env->status_vector) )
		return return_db_error(L, conn.env->status_vector);

	/* open up the transaction handle */
	isc_start_transaction(	env->status_vector, &conn.transaction, 1,
							&conn.db, (unsigned short)sizeof(isc_tpb),
							isc_tpb );

	/* return NULL on error */
	if ( CHECK_DB_ERROR(conn.env->status_vector) )
		return return_db_error(L, conn.env->status_vector);

	/* create the lua object and add the connection to the lock */
	res_conn = (conn_data*)lua_newuserdata(L, sizeof(conn_data));
	luasql_setmeta (L, LUASQL_CONNECTION_FIREBIRD);
	memcpy(res_conn, &conn, sizeof(conn_data));
	res_conn->closed = 0;   /* connect now officially open */

	/* register the connection */
	lua_registerobj(L, 1, env);
	++env->lock;

	return 1;
}
Exemple #19
0
static int os_execute (lua_State *L) {
  lua_pushinteger(L, system(luaL_optstring(L, 1, NULL)));
  return 1;
}
static int lua_carray_new(lua_State *L) {
  const char *type = luaL_optstring(L, 1, "double");

  int size;
  bool istable = lua_istable(L, 2);
  if (istable) {
#if LUA_VERSION_NUM == 502
    size = lua_rawlen(L, 2);
#else
    size = lua_objlen(L, 2);
#endif
  }
  else {
    size = luaL_optinteger(L, 2, 1);
  }
  structCArray *ud = (structCArray *)lua_newuserdata(L, sizeof(structCArray));

  ud->size = size;
  ud->type = type[0];
  ud->own = 1;

  int i;
  unsigned char *p_uchar;
  char *p_char;
  short *p_short;
  int *p_int;
  unsigned int *p_uint;
  float *p_float;
  double *p_double;

  switch (ud->type) {
  case 'b':
    p_uchar = new unsigned char[size];
    ud->ptr = p_uchar;
    if (istable) {
      for (i = 0; i < size; i++) {
	lua_pushinteger(L, i+1);
	// Lua stack: table, userdata, index (top)
	lua_gettable(L, -3);
	p_uchar[i] = lua_tointeger(L, -1);
	lua_pop(L, 1);
      }
    }
    break;
  case 'c':
    p_char = new char[size];
    ud->ptr = p_char;
    if (istable) {
      for (i = 0; i < size; i++) {
	lua_pushinteger(L, i+1);
	lua_gettable(L, -3);
	p_char[i] = lua_tointeger(L, -2);
	lua_pop(L, 1);
      }
    }
    break;
  case 's':
    p_short = new short[size];
    ud->ptr = p_short;
    if (istable) {
      for (i = 0; i < size; i++) {
	lua_pushinteger(L, i+1);
	lua_gettable(L, -3);
	p_short[i] = lua_tointeger(L, -2);
	lua_pop(L, 1);
      }
    }
    break;
  case 'i':
    p_int = new int[size];
    ud->ptr = p_int;
    if (istable) {
      for (i = 0; i < size; i++) {
	lua_pushinteger(L, i+1);
	lua_gettable(L, -3);
	p_int[i] = lua_tointeger(L, -2);
	lua_pop(L, 1);
      }
    }
    break;
  case 'u':
    p_uint = new unsigned int[size];
    ud->ptr = p_uint;
    if (istable) {
      for (i = 0; i < size; i++) {
	lua_pushinteger(L, i+1);
	lua_gettable(L, -3);
	p_uint[i] = lua_tointeger(L, -2);
	lua_pop(L, 1);
      }
    }
    break;
  case 'f':
    p_float = new float[size];
    ud->ptr = p_float;
    if (istable) {
      for (i = 0; i < size; i++) {
	lua_pushinteger(L, i+1);
	lua_gettable(L, -3);
	p_float[i] = lua_tonumber(L, -1);
	lua_pop(L, 1);
      }
    }
    break;
  case 'd':
    p_double = new double[size];
    ud->ptr = p_double;
    if (istable) {
      for (i = 0; i < size; i++) {
	lua_pushinteger(L, i+1);
	lua_gettable(L, -3);
	p_double[i] = lua_tonumber(L, -1);
	lua_pop(L, 1);
      }
    }
    break;
  default:
    ud->ptr = new char[size];
  }

  luaL_getmetatable(L, "carray_mt");
  lua_setmetatable(L, -2);
  return 1;
}