Your code still requires functions to be specially written to work from command line. I want to be able to call any function. I don't see what's wrong with the code I posted, as it does what I want.
Sorry for the short reply, I'm on an iPod.
EDIT:
Oops, what i meant by command line was a type of 'in-game console', and not the CL$() function. Sorry about that.
I have posted the function i am using now, it is my own version of
Call Function Name, except asks for ReturnType$,Format$,ArgList$.
// Constants for Argument datatype function pointers
#CONSTANT INT_ARG_PTR Get Ptr To Function("as_integer")
#CONSTANT FLOAT_ARG_PTR Get ptr To Function("as_float")
#CONSTANT STRING_ARG_PTR Get ptr To Function("as_string")
#CONSTANT BYTE_ARG_PTR Get ptr To Function("as_byte")
#CONSTANT WORD_ARG_PTR Get ptr To Function("as_word")
#CONSTANT DWORD_ARG_PTR Get ptr To Function("as_dword")
// Constants for Return datatype function pointers
#CONSTANT VOID_RET_PTR Get ptr To Function("ret_void")
#CONSTANT INT_RET_PTR Get ptr To Function("ret_integer")
#CONSTANT FLOAT_RET_PTR Get ptr To Function("ret_float")
#CONSTANT STRING_RET_PTR Get ptr To Function("ret_string")
#CONSTANT BYTE_RET_PTR Get ptr To Function("ret_byte")
#CONSTANT WORD_RET_PTR Get ptr To Function("ret_word")
#CONSTANT DWORD_RET_PTR Get ptr To Function("ret_dword")
// --- start here ---
// CL: MyPrint(5,Hello World,3.14)
// I would use my own parsing functions to get the return type and arg types
MyCallFunctionName("MyPrint","v","isf","5,Hello World,3.14")
// CL: MyRND(20,40)
Rand$ = MyCallFunctionName("MyRND","i","ii","20,40")
Print Rand$
// CL: GetString()
string$ = MyCallFunctionName("MyString","s","","")
Print string$
// --- end here ---
Wait Key : end
// These three functions are written normally(no special code to get them to work)
Function MyString()
s$ = "Hello World"
Endfunction s$
Function MyRND(MinVal,MaxVal)
Range = MaxVal-MinVal
R = RND(Range)+MinVal
Endfunction R
Function MyPrint(Arg1 as integer,Arg2 as string,Arg3 as float)
Print "Int: ",Arg1
Print "String: ",Arg2
Print "Float: ",Arg3
Endfunction
// this can call any function
Function MyCallFunctionName(Func$,ReturnType$,Format$,ArgList$)
// Get Pointer to the function name
FuncPtr = Get Ptr To Function(Func$)
// check if pointer exists
if FuncPtr<>0
// define variables
ArgInt as Integer
ArgFloat as Float
ArgString as String
ArgByte as Byte
ArgWord as Word
ArgDword as Dword
ArgCount = Fast LEN(Format$)
if ArgCount<>0
Split String ArgList$,","
LOCAL DIM ArgPtr(ArgCount) as DWORD
LOCAL DIM ArgStr(ArgCount) as String
// set ArgPtr(?) to the correct arg-type function
for arg=1 to ArgCount
Type$ = Mid$(Format$,arg)
Select Type$
Case "i": // integer
ArgPtr(arg) = INT_ARG_PTR
ArgInt = Val(Get Split Word$(Arg))
ArgStr(arg) = Str$(ArgInt)
Endcase
Case "f": // float
ArgPtr(arg) = FLOAT_ARG_PTR
ArgFloat = Val(Get Split Word$(Arg))
ArgStr(arg) = Str$(ArgFloat)
Endcase
Case "s": // string
ArgPtr(arg) = STRING_ARG_PTR
ArgString = Get Split Word$(Arg)
ArgStr(arg) = ArgString
Endcase
Case "b": // byte
ArgPtr(arg) = BYTE_ARG_PTR
ArgByte = Val(Get Split Word$(Arg))
ArgStr(arg) = Str$(ArgByte)
Endcase
Case "w": // word
ArgPtr(arg) = WORD_ARG_PTR
ArgWord = Val(Get Split Word$(Arg))
ArgStr(arg) = Str$(ArgWord)
Endcase
Case "d": // dword
ArgPtr(arg) = DWORD_ARG_PTR
ArgDword = Val(Get Split Word$(Arg))
ArgStr(arg) = Str$(ArgDword)
Endcase
Case Default // type not reconized
ArgPtr(arg) = STRING_ARG_PTR
ArgString = Get Split Word$(Arg)
ArgStr(arg) = ArgString
Endcase
Endselect
next arg
Endif
// set ReturnPtr to correct return-type function
Select ReturnType$
Case "v": // void
ReturnPtr = VOID_RET_PTR
Endcase
Case "i": // integer
ReturnPtr = INT_RET_PTR
Endcase
Case "f": // float
ReturnPtr = FLOAT_RET_PTR
Endcase
Case "s": // string
ReturnPtr = STRING_RET_PTR
Endcase
Case "b": // byte
ReturnPtr = BYTE_RET_PTR
Endcase
Case "w": // word
ReturnPtr = WORD_RET_PTR
Endcase
Case "d": // dword
ReturnPtr = DWORD_RET_PTR
Endcase
Case Default // type not reconized
ReturnPtr = VOID_RET_PTR
Endcase
Endselect
// function calls 0 to 9 parameters
Select ArgCount
Case 0:
Result$=Call Function Ptr(ReturnPtr,Call Function Ptr(FuncPtr))
Endcase
Case 1:
Result$=Call Function Ptr(ReturnPtr,Call Function Ptr(FuncPtr, Call Function Ptr(ArgPtr(1),ArgStr(1))))
Endcase
Case 2:
Result$=Call Function Ptr(ReturnPtr,Call Function Ptr(FuncPtr, Call Function Ptr(ArgPtr(1),ArgStr(1)), Call Function Ptr(ArgPtr(2),ArgStr(2))))
Endcase
Case 3:
Result$=Call Function Ptr(ReturnPtr,Call Function Ptr(FuncPtr, Call Function Ptr(ArgPtr(1),ArgStr(1)), Call Function Ptr(ArgPtr(2),ArgStr(2)), Call Function Ptr(ArgPtr(3),ArgStr(3))))
Endcase
Case 4:
Result$=Call Function Ptr(ReturnPtr,Call Function Ptr(FuncPtr, Call Function Ptr(ArgPtr(1),ArgStr(1)), Call Function Ptr(ArgPtr(2),ArgStr(2)), Call Function Ptr(ArgPtr(3),ArgStr(3)), Call Function Ptr(ArgPtr(4),ArgStr(4))))
Endcase
Case 5:
Result$=Call Function Ptr(ReturnPtr,Call Function Ptr(FuncPtr, Call Function Ptr(ArgPtr(1),ArgStr(1)), Call Function Ptr(ArgPtr(2),ArgStr(2)), Call Function Ptr(ArgPtr(3),ArgStr(3)), Call Function Ptr(ArgPtr(4),ArgStr(4)), Call Function Ptr(ArgPtr(5),ArgStr(5))))
Endcase
Case 6:
Result$=Call Function Ptr(ReturnPtr,Call Function Ptr(FuncPtr, Call Function Ptr(ArgPtr(1),ArgStr(1)), Call Function Ptr(ArgPtr(2),ArgStr(2)), Call Function Ptr(ArgPtr(3),ArgStr(3)), Call Function Ptr(ArgPtr(4),ArgStr(4)), Call Function Ptr(ArgPtr(5),ArgStr(5)), Call Function Ptr(ArgPtr(6),ArgStr(6))))
Endcase
Case 7:
Result$=Call Function Ptr(ReturnPtr,Call Function Ptr(FuncPtr, Call Function Ptr(ArgPtr(1),ArgStr(1)), Call Function Ptr(ArgPtr(2),ArgStr(2)), Call Function Ptr(ArgPtr(3),ArgStr(3)), Call Function Ptr(ArgPtr(4),ArgStr(4)), Call Function Ptr(ArgPtr(5),ArgStr(5)), Call Function Ptr(ArgPtr(6),ArgStr(6)), Call Function Ptr(ArgPtr(7),ArgStr(7))))
Endcase
Case 8:
Result$=Call Function Ptr(ReturnPtr,Call Function Ptr(FuncPtr, Call Function Ptr(ArgPtr(1),ArgStr(1)), Call Function Ptr(ArgPtr(2),ArgStr(2)), Call Function Ptr(ArgPtr(3),ArgStr(3)), Call Function Ptr(ArgPtr(4),ArgStr(4)), Call Function Ptr(ArgPtr(5),ArgStr(5)), Call Function Ptr(ArgPtr(6),ArgStr(6)), Call Function Ptr(ArgPtr(7),ArgStr(7)), Call Function Ptr(ArgPtr(8),ArgStr(8))))
Endcase
Case 9:
Result$=Call Function Ptr(ReturnPtr,Call Function Ptr(FuncPtr, Call Function Ptr(ArgPtr(1),ArgStr(1)), Call Function Ptr(ArgPtr(2),ArgStr(2)), Call Function Ptr(ArgPtr(3),ArgStr(3)), Call Function Ptr(ArgPtr(4),ArgStr(4)), Call Function Ptr(ArgPtr(5),ArgStr(5)), Call Function Ptr(ArgPtr(6),ArgStr(6)), Call Function Ptr(ArgPtr(7),ArgStr(7)), Call Function Ptr(ArgPtr(8),ArgStr(8)), Call Function Ptr(ArgPtr(9),ArgStr(9))))
Endcase
Endselect
Else
Exit Prompt "function '"+func$+"' does not exist!","Error"
End
Endif
Endfunction Result$
// Argument String to Types functions
function as_string(v as string)
endfunction v
function as_integer(v as string)
result as integer
result = Val(v)
endfunction result
function as_float(v as string)
result as float
result = Val(v)
endfunction result
function as_byte(v as string)
result as byte
result = Val(v)
endfunction result
function as_word(v as string)
result as word
result = Val(v)
endfunction result
function as_dword(v as string)
result as dword
result = Val(v)
endfunction result
// return type to string functions
function ret_void(v)
result$ = ""
Endfunction result$
function ret_string(v as string)
Endfunction v
function ret_integer(v as integer)
Result$ = Str$(v)
Endfunction result$
function ret_float(v as float)
Result$ = Str$(v)
Endfunction result$
function ret_byte(v as byte)
Result$ = Str$(v)
Endfunction result$
function ret_word(v as word)
Result$ = Str$(v)
Endfunction result$
function ret_dword(v as dword)
Result$ = Str$(v)
Endfunction result$
As you can see,
MyCallFunctionName can call any function in the code, with out needing them to be specially written for them to work. For example, i might have a function that changes the level, which gets called every time the player finishes a level. I want the ability to call this function and all other functions through the in-game console.