Open-source News

Intel's Mesa Drivers Begin Preparing For The New Xe Kernel Driver

Phoronix - Thu, 02/09/2023 - 22:00
One of the open-source Intel Linux graphics driver milestones we have to look forward to this year is the introduction of the new "Xe" kernel graphics driver to effectively succeed the existing "i915" Direct Rendering Manager driver for recent generations of Intel graphics. More prep code was merged this week to Mesa's Intel "ANV" Vulkan driver in preparing to be able to make use of that new kernel mode driver once its upstreamed into the Linux kernel...

GTK5 Development Likely To Heat Up Following GTK 4.12

Phoronix - Thu, 02/09/2023 - 20:00
A new GTK blog post summarized a recent meet-up of GTK core developers for better sorting out active GTK4 work as well as some planning toward GTK5...

A Call For More Collaboration & Harmony Among BSD Hardware Drivers

Phoronix - Thu, 02/09/2023 - 19:36
The BSD operating system projects tend to not receive as much support from hardware vendors as Linux and their driver support is made even more fragmented on the BSD side due to many subtle as well as not so subtle differences between the major BSDs. NetBSD developer Pierre Pronchery has proposed more "harmony" among BSD drivers with increased collaboration between the major BSD players on driver development...

FreeType 2.13 Released With New Qt-Based Font Program

Phoronix - Thu, 02/09/2023 - 19:00
FreeType 2.13 is out today as the newest version of this widely-used font rendering library. New to FreeType 2.13 is a new Qt-based demo program...

More Aquacomputer Devices To Be Supported With Linux 6.3

Phoronix - Thu, 02/09/2023 - 18:50
Over the past two years since an Aquacomputer HWMON driver was first introduced to the mainline Linux kernel, it's continued to be extended to support more products from this German PC cooling/peripheral retailer. With Linux 6.3 additional Aquacomputer components are now supported by this kernel driver...

Start developing for WebAssembly with our new guide

opensource.com - Thu, 02/09/2023 - 16:00
Start developing for WebAssembly with our new guide sethkenlon Thu, 02/09/2023 - 03:00

Over the past few decades, the web browser has endured as the most popular cross-platform application. Looking at the browser from a different angle, it is one of the most popular platforms for application delivery. Think of all the websites you use that take the place of activities you used to do with software running on your desktop. You're still using software, but you're accessing it through a browser, and it's running on somebody else's Linux server. In the eternal effort to optimize the software we all use, the world of software development introduced WebAssembly back in 2019 as a way to run compiled code through a web browser. Application performance is better than ever, and the options for coding go far beyond the usual list of PHP, Python, and JavaScript.

Programming and development Red Hat Developers Blog Programming cheat sheets Try for free: Red Hat Learning Subscription eBook: An introduction to programming with Bash Bash shell scripting cheat sheet eBook: Modernizing Enterprise Java An open source developer's guide to building applications A target and a language

One of the powerful but also most confusing things about WebAssembly is that the term "webassembly" refers to both a language and a target. WebAssembly is an assembly language, but not many people choose to write code directly in assembly. Even the assembly language is ultimately converted to a binary format, which is what a computer requires to run code. This binary format is also called WebAssembly. This is good, though, because it means that you can use your choice of languages to write something that's ultimately delivered in WebAssembly, including C, C++, Rust, Javascript, and many others.

The gateway into WebAssembly is Emscripten, an LLVM compiler toolchain that produces WebAssembly from your code.

Install Emscripten

To install Emscripten on your Linux or macOS computer, use Git:

$ git clone \ https://github.com/emscripten-core/emsdk.git

Change directory into the emsdk directory and run the install command:

$ ./emsdk install latest $ ./emsdk activate latest

Everything in the Emscripten toolchain is installed within the emsdk directory and has no effect on the rest of your system. For this reason, before you use emsdk, you must source its environment:

$ source ./emsdk_env.sh

If you plan on using emsdk often, you can also source its environment setup script in .bashrc.

To install Emscripten on Windows, you can run Linux in the WSL environment.

Visit the Emscripten website for more information on installation.

Hello world

Here's a simple "hello world" application in written in C++.

#include <iostream> using namespace std; int main() { cout << "Hello world"; return 0; }

Test it as a standard binary for your system first:

$ g++ hello.cpp -o world $ ./world Hello world

Seeing that it works as expected, use emcc to build it as WebAssembly:

$ emcc hello.cpp -o world.html

Finally, run it with emrun:

$ emrun ./world.html

The emrun utility is a convenience command for local testing. When you host your application on a server, emrun isn't necessary.

Learning more about WebAssembly

Developing for WebAssembly can go in many different directions, depending on what you already know and what you're trying to build. If you know C or C++, then you can write your project using those. If you're learning Rust, then you can use Rust. Even Python code can use the Pyodide module to run as WebAssembly. You have lots of options, and there's no wrong way to start (there's even a COBOL-to-WebAssembly compiler). If you're keen to get started with WebAssembly, download our complimentary eBook.

Developing for WebAssembly can go in many different directions, depending on what you already know and what you're trying to build. Download our new guide to WebAssembly.

Image by:

opensource.com

Programming What to read next A guide to WebAssembly This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Learn Tcl by writing a simple game

opensource.com - Thu, 02/09/2023 - 16:00
Learn Tcl by writing a simple game JamesF Thu, 02/09/2023 - 03:00

My path to Tcl started with a recent need to automate a difficult Java-based command-line configuration utility. I do a bit of automation programming using Ansible, and I occasionally use the expect module. Frankly, I find this module has limited utility for a number of reasons including: difficulty with sequencing identical prompts, capturing values for use in additional steps, limited flexibility with control logic, and so on. Sometimes you can get away with using the shell module instead. But sometimes you hit that ill-behaving and overly complicated command-line interface that seems impossible to automate.

In my case, I was automating the installation of one of my company's programs. The last configuration step could only be done through the command-line, through several ill-formed, repeating prompts and data output that needed capturing. The good old traditional Expect was the only answer. A deep understanding of Tcl is not necessary to use the basics of Expect, but the more you know, the more power you can get from it. This is a topic for a follow-up article. For now, I explore the basic language constructs of Tcl, which include user input, output, variables, conditional evaluation, looping, and simple functions.

Install Tcl

On a Linux system, I use this:

# dnf install tcl # which tclsh /bin/tclsh

On macOS, you can use Homebrew to install the latest Tcl:

$ brew install tcl-tk $ which tclsh /usr/local/bin/tclshGuess the number in Tcl

Start by creating the basic executable script numgame.tcl:

$ touch numgame.tcl $ chmod 755 numgame.tcl

And then start coding in your file headed up by the usual shebang script header:

#!/usr/bin/tclsh

Here are a few quick words about artifacts of Tcl to track along with this article.

The first point is that all of Tcl is considered a series of strings. Variables are generally treated as strings but can switch types and internal representations automatically (something you generally have no visibility into). Functions may interpret their string arguments as numbers ( expr) and are only passed in by value. Strings are usually delineated using double quotes or curly braces. Double quotes allow for variable expansion and escape sequences, and curly braces impose no expansion at all.

The next point is that Tcl statements can be separated by semicolons but usually are not. Statement lines can be split using the backslash character. However, it's typical to enclose multiline statements within curly braces to avoid needing this. Curly braces are just simpler, and the code formatting below reflects this. Curly braces allow for deferred evaluation of strings. A value is passed to a function before Tcl does variable substitution.

Finally, Tcl uses square brackets for command substitution. Anything between the square brackets is sent to a new recursive invocation of the Tcl interpreter for evaluation. This is handy for calling functions in the middle of expressions or for generating parameters for functions.

Procedures

Although not necessary for this game, I start with an example of defining a function in Tcl that you can use later:

proc used_time {start} { return [expr [clock seconds] - $start] }

Using proc sets this up to be a function (or procedure) definition. Next comes the name of the function. This is then followed by a list containing the parameters; in this case 1 parameter {start} and then followed by the function body. Note that the body curly brace starts on this line, it cannot be on the following line. The function returns a value. The returned value is a compound evaluation (square braces) that starts by reading the system clock [clock seconds] and does the math to subtract out the $start parameter.

Setup, logic, and finish

You can add more details to the rest of this game with some initial setup, iterating over the player's guesses, and then printing results when completed:

set num [expr round(rand()*100)] set starttime [clock seconds] set guess -1 set count 0 puts "Guess a number between 1 and 100" while { $guess != $num } { incr count puts -nonewline "==> " flush stdout gets stdin guess if { $guess < $num } { puts "Too small, try again" } elseif { $guess > $num } { puts "Too large, try again" } else { puts "That's right!" } } set used [used_time $starttime] puts "You guessed value $num after $count tries and $used elapsed seconds"

Programming and development Red Hat Developers Blog Programming cheat sheets Try for free: Red Hat Learning Subscription eBook: An introduction to programming with Bash Bash shell scripting cheat sheet eBook: Modernizing Enterprise Java An open source developer's guide to building applications

The first set statements establish variables. The first two evaluate expressions to discern a random number between 1 and 100, and the next one saves the system clock start time.

The puts and gets command are used for output to and input from the player. The puts I've used imply standard out for output. The gets needs the input channel to be defined, so this code specifies stdin as the source for terminal input from the user.

The flush stdout command is needed when puts omits the end-of-line termination because Tcl buffers output and it might not get displayed before the next I/O is needed.

From there the while statement illustrates the looping control structure and conditional logic needed to give the player feedback and eventually end the loop.

The final set command calls our function to calculate elapsed seconds for gameplay, followed by the collected stats to end the game.

Play it! $ ./numgame.tcl Guess a number between 1 and 100 ==> 100 Too large, try again ==> 50 Too large, try again ==> 25 Too large, try again ==> 12 Too large, try again ==> 6 Too large, try again ==> 3 That's right! You guessed value 3 after 6 tries and 20 elapsed seconds Continue learning

When I started this exercise, I doubted just how useful going back to a late 1990s fad language would be to me. Along the way, I found a few things about Tcl that I really enjoyed — my favorite being the square bracket command evaluation. It just seems so much easier to read and use than many other languages that overuse complicated closure structures. What I thought was a dead language was actually still thriving and supported on several platforms. I learned a few new skills and grew an appreciation for this venerable language.

Check out the official site over at https://www.tcl-lang.org. You can find references to the latest source, binary distributions, forums, docs, and information on conferences that are still ongoing.

Explore the basic language constructs of Tcl, which include user input, output, variables, conditional evaluation, looping, and simple functions.

Image by:

Opensource.com

Programming What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Pages