(Last updated: 29/01/20)
PowerBLua
PowerBLua � un mio piccolo contributo alla comunit� di sviluppatori
PowerBASIC.
Si tratta di un wrapper per Lua, un linguaggio di
programmazione semplice e potente progettato per estendere e integrare altre
applicazioni.
Al momento, solo un subset dell'API � implementato ma, grazie alla flessibilit�
di Lua, � gi� pi� che sufficente per realizzare qualcosa di interessante.
Lua API functions
|
State management:
|
lua_open,
lua_close
|
|
Libraries management:
|
luaopen_base,
luaopen_debug,
luaopen_io,
luaopen_loadlib,
luaopen_math,
luaopen_string,
luaopen_table
|
|
Execute:
|
lua_dostring,
lua_dofile
|
|
Stack manipulation:
|
lua_gettop,
lua_settop,
lua_pushvalue,
lua_remove,
lua_insert,
lua_replace
|
|
Pushing onto the Stack:
|
lua_pushnumber,
lua_pushcclosure,
lua_pushstring
|
|
Getting from the Stack:
|
lua_toboolean,
lua_tonumber,
lua_tostring,
lua_tocfunction,
lua_touserdata
|
|
Stack values comparisions:
|
lua_equal,
lua_rawequal,
lua_lessthan
|
|
Type checking:
|
lua_type,
lua_isnil,
lua_isboolean,
lua_isnumber,
lua_isstring,
lua_istable,
lua_isfunction,
lua_iscfunction,
lua_isuserdata,
lua_islightuserdata,
|
|
Misc:
|
lua_settable,
lua_strlen
|
PowerBASIC wrapper functions / helpers
PBLua_Register
PBLua_DoString
PBLua_DoFile
PBLua_GetString
PBLua_SetValue
PBLua_GetValue
Esempio
PowerBASIC source: minmax.bas
' ===================================================================
' 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)
PRINT "PB : Finished! Press any key"
WAITKEY$
END FUNCTION
|
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
|
Download
PowerBLua (sorgenti & esempi), 10KB ZIP
Lua 5.0 binaries (Lua, LuaC & Lua.dlls), 182KB ZIP
Change Log
06/07/04:
+ Aggiunto un altro esempio: uno spellchecker.
03/03/04:
* Sistemato un bug nella funzione PBLua_GetValue.
10/02/04:
+ Le funzioni Lua Do* ora ritornano un eventuale codice errore.
09/02/04:
+ Aggiunte altre funzioni dell'API.
+ Aggiunto un altro esempio (riguardo l'uso di Lua per valutare espressioni).
08/02/04:
* Aggiornato per il supporto a Lua 5.0.
+ Aggiunto un package con Lua, LuaC e una Lua.DLL custom.
04/02/04:
+ Aggiunte il codice per altre funzioni dell'API.
+ Aggiunto un altro esempio.
03/02/04:
+ Aggiunti un paio di esempi e un po' di info.
02/02/04:
- Prima release preliminare!
|
|