Code Monkey home page Code Monkey logo

td-vala's Introduction

TDLib vala

TDLib json interface (tdjson) for vala.

Using tdjson in vala

First you must build TDLib on your machine.

Then you need to link libtdjson.so shared library with your vala app/file.

Example

Here is an example code of using TDJson in vala:

public static void log_callback(int log_level, string message){
    print("LOG: "+ message);
}

void main () {
    // We need a client id (aka instance id) to deal with TDLib. 
    int client_id = TDJsonApi.create_client_id();

    //  Disable default TDLib log stream
    string setLogResult = TDJsonApi.execute("{\"@type\": \"setLogStream\", \"log_stream\": {\"@type\": \"logStreamEmpty\"}}");
    print(setLogResult);
    print("\n");

    //  Set log callback 
    TDJsonApi.set_log_message_callback(1024, (TDJsonApi.log_message_callback_ptr) log_callback);

    //  Set TDLib log verbosity level to 1023 (log everything)
    TDJsonApi.execute("{\"@type\": \"setLogVerbosityLevel\", \"new_verbosity_level\": 1023}");
    
    TDJsonApi.send(client_id, "{\"@type\": \"getOption\", \"name\": \"version\"");
    print(TDJsonApi.receive(10));
}

Build example

By default TDLib build instructions installs TDLib in td/tdlib.

Using valac:

  • If TDLib is installed on your home directory:

    export TDLIB_PATH=$HOME/td/tdlib
    export LD_LIBRARY_PATH=$TDLIB_PATH/lib
    valac --vapidir . --pkg tdjson -X -L$LD_LIBRARY_PATH -X -ltdjson -X -I$TDLIB_PATH/include example.vala
  • If TDLib is installed in /usr/local (recommended):

    valac --vapidir . --pkg tdjson -X -ltdjson example.vala
Run
./example

td-vala's People

Contributors

aymenjd avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.