#!/usr/bin/env ascript
# extracts constant definitions and function declarations from gl.h and
# generates a template for an AScript module
import(re)

lines = open("glu.h").readlines()
consts = (re.match(r"^#define\s+(GLU_\w+)", lines):xiter):*group(1)
funcnames = (re.match(r"APIENTRY\s+(\w+)", lines):xiter):*group(1)
padlen = consts:*len().max() + 1
printf("""
// glu.%s():void
AScript_DeclareFunction(%s)
{
	SetMode(RSLTMODE_Void, MAP_Off, FLAT_Off);
}

AScript_ImplementFunction(%s)
{
	return Value::Null;
}
""", funcnames, funcnames, funcnames)
printf("""
// Module entry
AScript_ModuleEntry()
{
""")
printf("\t// value assignment\n")
printf("\tAScript_AssignValue(%-*s Value(%s));\n", padlen, consts + ",", consts)
printf("\t// function assignment\n")
printf("\tAScript_AssignFunction(%s);\n", funcnames)
printf("}\n")
