【HSP3】DXライブラリのDxDLL.cs(C#)をHSPのasに変換するアレ(手抜き)

関数と定数が DxLib.as として出力されます。めっちゃ手抜きです。

関数と定数が DxLib.as として出力されます。めっちゃ手抜きです。

#module
// (1byte)
#defcfunc searchR1 str _in, int ps, int sh
idx = -1
in = _in
max = strlen(in)
repeat max, ps
if peek(in, max-cnt) == sh : idx = max-cnt : break
loop
return idx
// instr
#defcfunc instrl var s1, str s2
ind = 0
repeat
res = instr(s1, ind, s2)
if res == -1 : break
ind += res + 1
loop
return ind-1
#defcfunc GetMacroName str _tmp, var macro, var const
sdim tmp, 1024
tmp = _tmp
sdim macro, 128
sdim const, 128
flag = 0
if instr(tmp, 0, "public const int ") != -1{
flag = 1
sdim res, 128
split tmp, " ", res
;markpos = -1
repeat length(res)
if res(cnt) == "="{
tmpcnt = cnt
// ()
repeat tmpcnt
tmpcnt--
if res(tmpcnt) != ""{
macro = res(tmpcnt)
break
}
loop
// ()
tmpcnt = cnt + 1 //
sdim tmpconst, 128
repeat length(res)-tmpcnt, tmpcnt
tmpconst += res(cnt)+" "
loop
//
tmpconst = strtrim(tmpconst, 0, ' ')
const = strtrim(tmpconst, 0, ';')
//
}
loop
}
return flag
#defcfunc GetFuncName str _tmp, var _fnc, array _arg
sdim tmp, 1024
tmp = _tmp
sdim _arg, 256 : sdim _fnc, 128
num = -1
if instr(tmp, 0, "extern") != -1{
num = 0
ks = instr(tmp, 0, "(")
ke = instrl(tmp, ")")
if ks != -1 | ke != -1{
args = strmid(tmp, ks+1, ke-ks-1)
tmp2 = strmid(tmp, 0, ks)
tmp2 = strtrim(tmp2, 0, ' ')
ps = searchR1(tmp2, 0, ' ')
if ps != -1 {
//
tmp3 = strmid(tmp2, ps, strlen(tmp2))
_fnc = strtrim(tmp3, 0, ' ')
//
//
cargs = args
cargs = strtrim(cargs, 3, ' ')
cargs = strtrim(cargs, 3, '\t')
if cargs == "" : num = 0 : return num
//
sdim tmp2
split args, ",", tmp2
num = stat
repeat num
tmp3 = tmp2(cnt)
tmp3 = strtrim(tmp3, 3, '\t')
tmp3 = strtrim(tmp3, 0, ' ')
ps = searchR1(tmp3, 0, ' ')
if ps != -1{
tmp4 = strmid(tmp3, 0, ps)
tmp4 = strtrim(tmp4, 0, ' ')
_arg(cnt) = tmp4
}
loop
}
}
}
return num
#global
dialog "cs",16
if stat == 0 : end
fname = refstr
notesel buf
noteload fname
sdim def, 1024*512
sdim fncs, 1024*512
repeat notemax
noteget tmp, cnt
if GetMacroName(tmp, macro, const){
def += "#define global "+ macro +" "+ const +"\n"
}
num = GetFuncName(tmp, fnc, arg)
if num != -1{
sdim outargs
repeat num
if arg(cnt) == "int" || arg(cnt) == "ulong"{
outargs += "int"
}else:if arg(cnt) == "System.Text.StringBuilder" || arg(cnt) == "string"{
outargs += "str"
}else:if arg(cnt) == "double"{
outargs += "double"
}else:if arg(cnt) == "float"{
outargs += "float"
}else{
outargs += "sptr"
}
// ,
if cnt != num - 1 : outargs += ","
loop
// dx_ ()
split fnc, "dx_", fnc2
fncs += "#func global "+ fnc2(1) +" \""+ fnc +"\" "+outargs+"\n"
}
loop
sdim outbuf, 1024*512
notesel outbuf
noteadd "#ifndef __DXLIB__"
noteadd "#define __DXLIB__"
noteadd "#uselib \"DxLib.dll\""
noteadd fncs
noteadd def
noteadd "#endif"
notesave "DxLib.as"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX