hi mark, I am quite new here. my question belongs to the topic "lua + powerbasic". can you tell me how I can get with PBWIN the "minmax" example to run ?
' ===================================================================
' This sample show how to register/export PowerBASIC functions to Lua
' ===================================================================
' Include the necessary declarations
#INCLUDE "PowerBLua.INC"
' This is the function exported to Lua
FUNCTION MinMax CDECL (BYVAL pLuaHandle AS DWORD) AS DWORD
DIM NumPar AS LONG
DIM i AS LONG
DIM Num AS DOUBLE
DIM MaxNum AS DOUBLE
DIM MinNum AS DOUBLE
' Get the number of parameters passed on the Virtual Stack
' by the calling Lua code
NumPar = Lua_GetTop(pLuaHandle)
' Pop all parameters from the VS and evaluate them
FOR i = 1 TO NumPar
' Peek the specified VS element
Num = Lua_ToNumber(pLuaHandle, i)
MaxNum = MAX(Num, MaxNum)
IF MinNum = 0 THEN
MinNum = Num
ELSE
MinNum = MIN(Num, MinNum)
END IF
NEXT i
' Push the results on the VS
Lua_PushNumber(pLuaHandle, MinNum)
Lua_PushNumber(pLuaHandle, MaxNum)
' Set number of returned parameters
FUNCTION = 2
END FUNCTION
FUNCTION PBMAIN
DIM LuaHandle AS DWORD
' Create a Lua state
LuaHandle = Lua_Open()
' Load the base Lua library (needed for 'print')
LuaOpen_Base(LuaHandle)
' Register the function to be called from Lua as PBMinMax
PBLua_Register(LuaHandle, "PBMinMax", CODEPTR(MinMax))
' Execute the Lua script from a file
PBLua_DoFile(LuaHandle, "minmax.lua")
' Release the Lua state
Lua_Close(LuaHandle)
MSGBOX "PB : Finished! Press any key"
END FUNCTION
this example works for me, but not with your example below at your website.
Lua source: minmax.lua
-- Show how to call a function registered in the embedding application
-- PBMinMax is a PowerBASIC function
Min, Max = PBMinMax(42, 2, 17, 33, 15, 1.5)
print("Lua: Min= ", Min, ", Max= ", Max, "\n")
Console output:
Lua: Min= 1.5, Max= 42
PB : Finished! Press any key
I cannot use Console, but would like to take msgbox
other examples are running (exxparser and hello). - perhaps you can help, would be nice!
best regards, frankolino