Lua Scripting in C#.

Slides:



Advertisements
Similar presentations
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
Advertisements

The Web Warrior Guide to Web Design Technologies
Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Using Java without BlueJ
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
IS 426: Information Systems Construction in Modern Society Downloading and exploring oracle development environments.
ASP.Net, Web Forms and Web Controls 1 Outline Introduction Simple HTTP Transaction System Architecture Creating and Running a Simple Web Form Example Web.
LEGO NXT Robot Programming Introduction to Programming a Lego NXT robot in Java.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Understanding Events and Exceptions Lesson 3. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understand events and event handling Understand.
XP Tutorial 5 Buttons, Behaviors, and Sounds. XP New Perspectives on Macromedia Flash MX Buttons Interactive means that the user has some level.
Neal Stublen Class Objectives  Develop an understanding of the.NET Framework  Gain proficiency using Visual Studio  Begin learning.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
1 Chapter 9 Writing, Testing, and Debugging Access Applications.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
© Minder Chen, ASP.NET 2.0: Introduction - 1 ASP.NET 2.0 Minder Chen, Ph.D. Framework Base Class Library ADO.NET: Data & XML.
© 2006 IBM Corporation IBM WebSphere Portlet Factory Architecture.
Web Services Week 2 Aims: Getting started with creating simple C# applications within Visual Studio.NET Objectives: –An introduction to the syntax of C#.NET.
JavaScript: Functions © by Pearson Education, Inc. All Rights Reserved.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
1 JavaScript in Context. Server-Side Programming.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
2010 Control System Writing and Reading the cRio Presented By: Frank Larkin Lansdale Catholic Robotics, Team 272 First 2010 Kickoff, Jan
COP 3330 Notes 1/12. Today's topics Downloading Java and Eclipse Hello World Basic control structures Basic I/O Strings.
Lecture 11 Dynamic link libraries. Differences between static libraries and DLLs In static library code is added to the executable. In DLL, the code is.
GEMVC. The Setup Folders Views Value Objects (VOs) Custom Events Service CFCs Controller Model Application Main MXML.
Copyright © Curt Hill Turtles The beginning of media computation.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Slide 1 VB Graphics Controls & Timer Control. Slide 2 Default Controls.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
Chapter 1 Introduction to PHP Part 1. Textbook’s Code DOWNLOADS PHP and MySQL for Dynamic Web Sites Complete Set of Scripts.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
Debug in Visual Studio Windows Development Fundamentals LESSON 2.5A.
Beginning JavaScript 4 th Edition. Chapter 1 Introduction to JavaScript and the Web.
Building Custom Controls with ASP.NET and the Microsoft ®.NET Framework Rames Gantanant Microsoft Regional Director, Thailand
Week 1 Lecture 1 Slide 1 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton CP2028 Visual Basic Programming 2 v Week.
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
Internet & World Wide Web How to Program, 5/e.  JavaScript events  allow scripts to respond to user interactions and modify the page accordingly  Events.
C++ Exceptions.
The need for Programming Languages
Java Memory Management
Introduction to Operating Systems
Process concept.
Java Memory Management
Adding Buttons, Actions, and Sounds
Introduction to PHP Part 1
Delegates and Events 14: Delegates and Events
Testing and Debugging.
Introduction to Events
14 A Brief Look at JavaScript and jQuery.
Web Development in Microsoft Visual Studio 2013
Introduction to Operating Systems
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
Hands-on Introduction to Visual Basic .NET
CIS16 Application Development and Programming using Visual Basic.net
Double click Microsoft Visual Studio 2010 on the Computer Desktop
Python Syntax Errors and Exceptions
Tutorial 10: Programming with javascript
LUA 3D MIM 김현준.
C# COM Interoperability
GUI Programming in Visual Studio .NET
Presentation transcript:

Lua Scripting in C#

How to Set Things Up Download LuaInterface Unzip Source code is available to recompile if needed 51Net4 available from 3103 site (ready for .NET 4) Unzip lua51.dll and LuaInterface.dll Place these DLL files in your project Add them as Reference Add “using LuaInterface;” atop code

Adding the DLL references

The LuaInterface Object LuaInterface l = new Lua(); // executing a single command l.DoString("a=4"); //reading a variable Console.WriteLine(l["a"]); // finishing off l.Close();

Simple Lua Example

(internal runtime data) What’s Happening C# Code Main l Heap (Memory) LuaInterface Instance (internal runtime data) a 4

LuaInterface (LI) is Persistent Edit variables in script space Executing commands Writing to variables directly Note the value remains (i.e., think of them as properties within LI)

Running a Script In File C# Code Main l Heap (Memory) Script File (on Disk) LuaInterface Instance (internal runtime data) a Lua Code a = 4 4 LuaInterface.Lua l = new Lua(); l.DoFile(@"Scripts\SimpleScript.lua"); l.Close();

Errors… Must Change Property…

More Errors…

Solution: File Formatting

Lua and NET Interaction Heap (Memory) C# Code Main Worker w LuaInterface Instance (internal runtime data) MainProgram a Worker LuaInterface l string Data DisplaySomething() { … } 4 Script File (on Disk) Lua Code a = 4 MainProgram.Data = “Hello World” MainProgram:DisplaySomething()

Accessing CLR/NET Objects In Lua, we can access attributes using the dot (.) operator MainProgram.Data = "Hello World" We can also invoke methods using the colon (:) operator MainProgram:DisplaySomething()

Handling Events In C#, you can define new events public delegate void SimpleEventHandler(); public event EventHandler SimpleEvent; Then you can raise the event SimpleEvent(this, null); Subscribing to the event enables handling SimpleEvent += new SimpleEventHandler(DoFunction);

Handling Events in Lua function handle_event() a = a + 1 MainProgram:DisplayState() end function handle_event_different() a = a + 10 MainProgram.SimpleEvent:Add(handle_event) MainProgram.SimpleEvent:Add(handle_event_different) a = 0

Testing the Event Handler l = new Lua(); l["MainProgram"] = this; l.DoFile(@"Scripts\SimpleScript.lua"); Timer t = new Timer(new TimerCallback(TimerFired), null, 0, 1000); Console.ReadLine(); l.Close(); private void TimerFired(Object state) { SimpleEvent(this, null); } function handle_event() a = a + 1 MainProgram:DisplayState() end function handle_event_different() a = a + 10 MainProgram.SimpleEvent:Add(handle_event) MainProgram.SimpleEvent:Add(handle_event_different) a = 0

Further Reading http://luaforge.net/projects/luainterface/ http://www.chipmunkav.com/support/guide.pdf http://lua-users.org/wiki/LuaInterface http://karlagius.com/2007/09/29/luainterface/ http://penlight.luaforge.net/project-pages/penlight/packages/LuaInterface/ http://www.godpatterns.com/2005/07/using-lua-scripting-for-games.html