Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

PowerBLua: runtime expression parsing made simpe

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PowerBLua: runtime expression parsing made simpe

    ... Simple! made Simple, not "simpe"!

    Code:
    ' ===================================================================
    ' This sample show how to use (PowerB)Lua to parse expressions
    ' ===================================================================
    
    
    ' Include the necessary declarations
    
    #INCLUDE "PowerBLua.INC"
    
                                             
    FUNCTION PBMAIN
    
      DIM LuaHandle AS DWORD
      
      ' Create a Lua state
      LuaHandle = Lua_Open()
    
      ' Load the base Lua library (needed for 'print')
      LuaOpen_Base(LuaHandle)
    
      ' This is the expression to evaluate
      Text$ = "(1 + 2 + 3 * (5 + 2) / 7) + 3 "
      PRINT "Expression: " Text$
      
      ' Execute expression with Lua
      ' Results will be assigned to global "Res"
      PRINT "Running Lua..."
      IF PBLua_DoString(LuaHandle, "Res = " & Text$) <> 0 THEN
        ' Lua returned an error!
        PRINT "Error!"
      ELSE
        ' Get the value of Lua global 'Res' (as a string)  
        PRINT "Result:"; VAL(PBLua_GetValue(LuaHandle, "Res"))
      END IF
      
      ' Release the Lua state
      Lua_Close(LuaHandle) 
    
      PRINT "PB : Finished! Press any key"
      WAITKEY$
    
    END FUNCTION
    Edit:

    - 10/02/04 Updated just to check the return code after PBLua_Do.

    ------------------
    Try TrID file identifier! Over 950 filetypes and counting...
    Give a powerfull scriptable Lua interface to your application with PowerBLua


    [This message has been edited by Marco Pontello (edited July 29, 2004).]
    -- The universe tends toward maximum irony. Don't push it.

    File Extension Seeker - Metasearch engine for file extensions / file types
    Online TrID file identifier | TrIDLib - Identify thousands of file formats

  • #2
    Sample console output:

    Code:
    Expression: (1 + 2 + 3 * (5 + 2) / 7) + 3
    Running Lua...
    Result: 9
    PB : Finished! Press any key
    Bye!


    ------------------
    Try TrID file identifier! Over 950 filetypes and counting...
    Give a powerfull scriptable Lua interface to your application with PowerBLua
    -- The universe tends toward maximum irony. Don't push it.

    File Extension Seeker - Metasearch engine for file extensions / file types
    Online TrID file identifier | TrIDLib - Identify thousands of file formats

    Comment

    Working...
    X