This is aboxtest.lua
"Includes" and a reminder on what ID number goes for what type of data.
Code:
require 'mui'
require "muidefs"
require "muifuncs"
require "cdata"
require 'abox'
require 'io'
-- TYPE_VOID 0x00
-- TYPE_BYTE 0x01
-- TYPE_UBYTE 0x02
-- TYPE_WORD 0x03
-- TYPE_UWORD 0x04
-- TYPE_LONG 0x05
-- TYPE_ULONG 0x06
-- TYPE_STRPTR 0x07
-- TYPE_C_STRUCT 0x08 obsolete
-- TYPE_BOOL 0x09
-- TYPE_APTR 0x10
-- TYPE_PTR 0x10000
Bunch of structs we are gonna use, note the "Window" is just a placeholder as I plan to support a "typed" pointer later on for when you never need to look inside a structure but just a handle for it.
Code:
Node =
{
name = "Node",
{"struct Node*", "ln_Succ"},
{"struct Node*", "ln_Pred"},
{types.UBYTE, "ln_Type"},
{types.BYTE, "ln_Pri"},
{types.STRPTR, "ln_Name"}
}
List =
{
name = "List",
{"struct Node*", "lh_Head"},
{"struct Node*", "lh_Tail"},
{"struct Node*", "lh_TailPred"},
{types.UBYTE, "lh_Type"},
{types.UBYTE, "lh_pad"}
}
Task =
{
name = "Task",
{"struct Node", "tc_Node"},
{types.UBYTE, "tc_Flags"},
{types.UBYTE, "tc_State"},
{types.BYTE, "tc_IDNestCnt"},
{types.BYTE, "tc_TDNestCnt"},
{types.ULONG, "tc_SigAlloc"},
{types.ULONG, "tc_SigWait"},
{types.ULONG, "tc_SigRecvd"},
{types.ULONG, "tc_SigExcept"},
{types.APTR, "tc_ETask"},
{types.APTR, "tc_ExceptData"},
{types.APTR, "tc_ExceptCode"},
{types.APTR, "tc_TrapData"},
{types.APTR, "tc_TrapCode"},
{types.APTR, "tc_SPReg"},
{types.APTR, "tc_SPLower"},
{types.APTR, "tc_SPUpper"},
{types.ULONG, "void1"}, --(*tc_Switch)(VOID); /*** OBSOLETE ***/
{types.ULONG, "void2"}, --(*tc_Launch)(VOID); /*** OBSOLETE ***/
{"struct List", "tc_MemEntry"},
{types.APTR, "tc_UserData"}
}
NewWindow =
{
name = "NewWindow",
{types.WORD, "LeftEdge"},
{types.WORD, "TopEdge"},
{types.WORD, "Width"},
{types.WORD, "Height"},
{types.UBYTE, "DetailPen"},
{types.UBYTE, "lockPen"},
{types.ULONG, "IDCMPFlags"},
{types.ULONG, "Flags"},
{"struct Gadget *", "FirstGadget"},
{"struct Image *", "CheckMark"},
-- {types.UBYTE+types.PTR, "Title"},
{types.STRPTR, "Title"},
{"struct Screen *", "Screen"},
{"struct BitMap *", "BitMap"},
{types.WORD, "MinWidth"},
{types.WORD, "MinHeight"},
{types.UWORD, "MaxWidth"},
{types.WORD, "MaxHeight"},
{types.UWORD, "Type"}
}
Window =
{
name = "Window",
{types.ULONG, "VOID"}
}
struct.register(Node)
struct.register(List)
struct.register(Task)
struct.register(NewWindow)
struct.register(Window)
Definition of the LibCalls we want to use.
Format is base,offset,return type, arg1 type, arg1 register (1- for D0-7, 8-13 for A0-A5),arg2 type..... LUA-Varargs
Code:
function abox.OpenLibrary(...) return abox.LibCall(abox.SysBase,-552,"Library",0x07,0x09,0x05,0x00,arg) end
function abox.CloseLibrary(...) return abox.LibCall(abox.SysBase,-414,0x00,"Library",0x08,arg) end
function abox.NewGetSystemAttrsA(...) return abox.LibCall(abox.SysBase,-906,0x05,0x10,0x08,0x05,0,0x05,0x01,"TagItem",0x09,arg) end
function abox.FindTask(...) return abox.LibCall(abox.SysBase,-294,"Task",arg) end
function abox.OpenWindowTagList(...) return abox.LibCall(abox.IntuitionBase,-606,"Window","NewWindow",0x08,"TagItem",0x09,arg) end
function abox.DisplayBeep(...) return abox.LibCall(abox.IntuitionBase,-96,0x00,0x05,0x08,arg) end
function abox.CloseWindow(...) return abox.LibCall(abox.IntuitionBase,-72,0x00,"Window",0x08,arg) end
function abox.Delay(...) return abox.LibCall(abox.DosBase,-198,0,5,1,arg) end
Some constants and an array to use as a string result (should have been UBYTE)
Code:
abox.SYSTEMINFOTYPE_REGUSER = 0x23c
abox.SYSTEMINFOTYPE_VENDOR = 0x236
abox.SYSTEMINFOTYPE_CPUCOUNT = 0x101
res_str = array.new(130,types.ULONG)
res_str[1] = 190
io.write(res_str[1].."n")
res_str.LUA_String and res_str.LUA_Int converts the raw data into a string or number.
Code:
res = abox.NewGetSystemAttrsA(res_str,130,abox.SYSTEMINFOTYPE_REGUSER,0)
xx = res_str.LUA_String
io.write(res_str.LUA_String.."n")
res = abox.NewGetSystemAttrsA(res_str,130,abox.SYSTEMINFOTYPE_VENDOR,0)
xx = res_str.LUA_String
io.write(res_str.LUA_String.."n")
res = abox.NewGetSystemAttrsA(res_str,130,abox.SYSTEMINFOTYPE_CPUCOUNT,0)
xx = res_str.LUA_String
io.write(res_str.LUA_Int.."n")
Setting a tasks priority actually works this way but is bad style for obvious reasons. Was only done to test if write access to an "embeeded" struct actually works (a struct inside a struct that is not just a pointer).
Code:
task =abox.FindTask(0)
node = task.tc_Node
--task.tc_Node.ln_Pri = -41
io.write(task.tc_Node.ln_Name.."n")
io.write(task.tc_Node.ln_Type.." typen")
io.write(task.tc_Node.ln_Pri.." prin")
io.write(task.tc_SigAlloc.."n")
Opening, using and closing some Libraries. Note that there are no checks for failure as those aren't implemented yet in abox.module.
At the moment on a failed OpenLibrary() it will just return struct_Library object pointing to 0.
Doing non MUI windows is not recommended off course and just done as a poof of concept.
Code:
abox.IntuitionBase = abox.OpenLibrary("intuition.library",0)
abox.DosBase = abox.OpenLibrary("dos.library",0)
nw = struct.new(NewWindow)
nw.LeftEdge = 300
nw.TopEdge = 400
nw.Width = 300
nw.Height = 200
nw.Title = "Test_Window"
nw.Type = 1 --WBENCHSCREEN
win = abox.OpenWindowTagList(nw,0)
abox.Delay(100)
abox.CloseWindow(win)
abox.DisplayBeep(0)
abox.CloseLibrary(abox.IntuitionBase)
abox.CloseLibrary(abox.DosBase)
[ Edited by Kronos 01.04.2023 - 19:15 ]