Mark0's software support board
September 06, 2010, 08:04:04 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to the new forum! Guests can posts without registration.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: PowerBLua :)  (Read 1902 times)
Frankolino
Newbie
*
Posts: 1


« on: January 05, 2010, 09:16:48 pm »

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 ?

Quote
' ===================================================================
' 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.

Quote
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 Smiley

other examples are running (exxparser and hello). - perhaps you can help, would be nice!

best regards, frankolino
Logged

Mark0
Administrator
Hero Member
*****
Posts: 896



WWW
« Reply #1 on: January 05, 2010, 09:31:11 pm »

The problem is that Lua's print function write to the standard output.
But you could simply create a simple PB function that write on a message box, and register / export that to the Lua environment, just as done for the MinMax() function in the sample.
Logged
Pages: [1]
  Print  

 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2001-2010, Lewis Media Valid XHTML 1.0! Valid CSS!
Page created in 9.185 seconds with 18 queries.