langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,31 @@
open Dlffi
let get_int = function Int v -> v | _ -> failwith "get_int"
let get_ptr = function Ptr v -> v | _ -> failwith "get_ptr"
let get_float = function Float v -> v | _ -> failwith "get_float"
let get_double = function Double v -> v | _ -> failwith "get_double"
let get_string = function String v -> v | _ -> failwith "get_string"
let () =
(* load the library *)
let xlib = dlopen "/usr/lib/libX11.so" [RTLD_LAZY] in
(* load the functions *)
let _open_display = dlsym xlib "XOpenDisplay"
and _default_screen = dlsym xlib "XDefaultScreen"
and _display_width = dlsym xlib "XDisplayWidth"
and _display_height = dlsym xlib "XDisplayHeight"
in
(* wrap functions to provide a higher level interface *)
let open_display ~name = get_ptr(fficall _open_display [| String name |] Return_ptr)
and default_screen ~dpy = get_int(fficall _default_screen [| (Ptr dpy) |] Return_int)
and display_width ~dpy ~scr = get_int(fficall _display_width [| (Ptr dpy); (Int scr) |] Return_int)
and display_height ~dpy ~scr = get_int(fficall _display_height [| (Ptr dpy); (Int scr) |] Return_int)
in
(* use our functions *)
let dpy = open_display ~name:":0" in
let screen_number = default_screen ~dpy in
let width = display_width ~dpy ~scr:screen_number
and height = display_height ~dpy ~scr:screen_number in
Printf.printf "# Screen dimensions are: %d x %d pixels\n" width height;
dlclose xlib;
;;

View file

@ -0,0 +1,13 @@
'Loading a shared library at run time and calling a function.
declare MessageBox(sys hWnd, String text,caption, sys utype)
sys user32 = LoadLibrary "user32.dll"
if user32 then @Messagebox = getProcAddress user32,"MessageBoxA"
if @MessageBox then MessageBox 0,"Hello","OxygenBasic",0
'...
FreeLibrary user32

View file

@ -0,0 +1 @@
install("function_name","G","gp_name","./test.gp.so");

View file

@ -0,0 +1,15 @@
use NativeCall;
constant libX11 = '/usr/lib/x86_64-linux-gnu/libX11.so.6';
sub XOpenDisplay(Str $s --> Int) is native(libX11) {*}
sub XCloseDisplay(Int $i --> Int) is native(libX11) {*}
if try my $d = XOpenDisplay ":0.0" {
say "ID = $d";
XCloseDisplay($d);
}
else {
say "No library {libX11}!";
say "Use this window instead --> ";
}

View file

@ -0,0 +1,37 @@
#INCLUDE "Win32API.inc"
FUNCTION PBMAIN () AS LONG
DIM hWnd AS LONG
DIM msg AS ASCIIZ * 14, titl AS ASCIIZ * 8
hWnd = LoadLibrary ("user32")
msg = "Hello, world!"
titl = "Example"
IF ISTRUE (hWnd) THEN
funcAddr& = GetProcAddress (hWnd, "MessageBoxA")
IF ISTRUE (funcAddr&) THEN
ASM push 0&
tAdr& = VARPTR(titl)
ASM push tAdr&
mAdr& = VARPTR(msg)
ASM push mAdr&
ASM push 0&
CALL DWORD funcAddr&
ELSE
GOTO epicFail
END IF
ELSE
GOTO epicFail
END IF
GOTO getMeOuttaHere
epicFail:
MSGBOX msg, , titl
getMeOuttaHere:
IF ISTRUE(hWnd) THEN
tmp& = FreeLibrary (hWnd)
IF ISFALSE(tmp&) THEN MSGBOX "Error freeing library... [shrug]"
END IF
END FUNCTION

View file

@ -0,0 +1,5 @@
if OpenLibrary(0, "USER32.DLL")
*MessageBox = GetFunction(0, "MessageBoxA")
CallFunctionFast(*MessageBox, 0, "Body", "Title", 0)
CloseLibrary(0)
endif

View file

@ -0,0 +1,7 @@
Prototype.l ProtoMessageBoxW(Window.l, Body.p-unicode, Title.p-unicode, Flags.l = 0)
If OpenLibrary(0, "User32.dll")
MsgBox.ProtoMessageBoxW = GetFunction(0, "MessageBoxW")
MsgBox(0, "Hello", "World")
CloseLibrary(0)
EndIf

View file

@ -0,0 +1,6 @@
#import std
#import flo
my_replacement = fleq/0.?/~& negative
abs = math.|fabs my_replacement