Skip to content

C code doesn't build on Windows #3

@soapdog

Description

@soapdog

The include ioctl.h is not a part of Visual Studio C stuff. I have a patched version here that works:

#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

#ifdef __linux__ 

#include <sys/ioctl.h>

int lua_winsize(lua_State *L) {
    struct winsize sz;

    ioctl(0, TIOCGWINSZ, &sz);

    lua_pushinteger(L, sz.ws_col);
    lua_pushinteger(L, sz.ws_row);

    return 2;
}
#elif _WIN32

#include <windows.h>
int lua_winsize(lua_State *L) {
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    int columns, rows;

    GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
    columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
    rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;

    lua_pushinteger(L, columns);
    lua_pushinteger(L, rows);

    return 2;
}


#endif

int luaopen_sirocco_winsize(lua_State *L) {
    lua_pushcfunction(L, lua_winsize);

    return 1;
}

Sorry for not sending a PR but downloaded the source as a zip.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions