PtokaX forum

Development Section => Your Developing Problems => Topic started by: andrea.vermetti on 26 May, 2005, 10:51:39

Title: a lua table into an array
Post by: andrea.vermetti on 26 May, 2005, 10:51:39
Hello people!!!!

I need a little help!!!!

How can get form a LUA FILE a teble and put it into an array

of string  in my C# class

string[] sss = xxxx["tableLua"].to String();


???


 
Title:
Post by: Dessamator on 26 May, 2005, 14:29:13
hmmm, in lua a table is almost like an array so it wouldnt change much! but then u want to convert it to a string? well, each item has it value in the array or table, so u can convert it easily just use tostring(xxx["tablelua"])
Title:
Post by: andrea.vermetti on 26 May, 2005, 14:32:54
Thanck you!!!!!,,, i'm goin' to try!!!!!!!
Title: it doesn't works....
Post by: andrea.vermetti on 26 May, 2005, 15:05:13
I get the table with this object (LuaInterface.LuaTable)

LuaInterface.LuaTable AWWAW= pluto.GetTable("a");

i get my table from lua file and now it becomes a c# objet....

so....

how can i test the lenght of AWWAW????

AWWAW.lenght();  it does not work
AWWAW.size();  it does not work


how can i get the AWWAW items and put them in my array

String[] str = new String[];

for (int i = 0, to  (AWWAW.lenght-1), i++)
{
 str  =  AWWAW(i)

}

HELP ME PLEASE!!!!!!!!!!!!
Title:
Post by: Optimus on 26 May, 2005, 16:21:08
Hi i'm using simulair code in my menu for robocop. So i know what ya mean or looking for, but i'm writting it in VB.Net so i can't tell ya how it should look in C#

I will ask some 1 else to help you...

Darn she got a lovely smile  :D

Laterss Optimus
Title:
Post by: andrea.vermetti on 26 May, 2005, 16:38:55
I'm using .net but in c# not vb...


how can i do the thinghs i'm doin with vb. dotnet????

how do you import lua DLLs?????

help me please....

if i could use vb......


i'm loosing a lot of time with c# (java)....

somebody say that's java is better......

HELP!!!!!!!!!!!!!
Title:
Post by: Optimus on 26 May, 2005, 17:18:50
QuoteI'm using .net but in c# not vb...


how can i do the thinghs i'm doin with vb. dotnet????

how do you import lua DLLs?????

help me please....

if i could use vb......


i'm loosing a lot of time with c# (java)....

somebody say that's java is better......

HELP!!!!!!!!!!!!!
' Import the LUA interface
Imports LuaInterface
Imports System.IO

Public Class frmRobocop
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Private LUA As LUA

    Private Sub frmRobocop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Intialize the Lua interface
        LUA = New Lua

        'Open LUA libraries
        LUA.OpenBaseLib()
        LUA.OpenDebugLib()
        LUA.OpenIOLib()
        LUA.OpenMathLib()
        LUA.OpenStringLib()
        LUA.OpenTableLib()

        Try
            'Dofile our needed files/tables
            LUA.DoFile(Application.StartupPath + "\system\robocoplua.lua") 'Store you lua code in here that can be called for later use
            LUA.DoFile(Application.StartupPath + "\settings.tbl")
            LUA.DoFile(Application.StartupPath + "\tbl\scriptlevel.tbl")
            ''LUA.DoFile(Application.StartupPath + "\tbl\inbuildlevel.tbl")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

        'Register object for use in lua
        LUA("TextBox_Txt") = TextBox_Txt

        'Trigger LUA event, called StartRoboCopLUA (this function is in my case stored in the file robocoplua.lua)
        Try
            LUA.GetFunction("StartRoboCopLUA").Call()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub


This gives you an idea what can be done

- Optimus
Title:
Post by: kepp on 26 May, 2005, 17:42:26
The LUA.NET package is great..
The only thing i miss of it is iteration of tables etc..

You must know position or key to enter value in table from C#

You use LuaTable LT = LUA.GetTable("MyTable");
now you enter it with LT[Number] or LT[Key]

If you really want to iterate over a table i recomend you to register a C# Array to LUA;

Create the C# Array and register it with LUA["MyCArray"] = ArrayObject;

now, you can write code with LUA.Dostring();
Iterate the table you want and insert it to the C# Array

for i,v in MyLuaTable do
   MyCArray:Add(v)
end
return 1;

Upon return 1 you are ready to access the content.
Just play around, you will figure it out somehow and eventually it will be clearer to you what i mean
Title: Andrea?
Post by: CaSaNoVa on 26 May, 2005, 18:16:23
Andrea ma sei la gnocca in foto? :D
Title:
Post by: NightLitch on 26 May, 2005, 18:18:59
Kepp that is not the right way to seduse a lady you know.

btw mate your KEY will never fit...  :D

Btw: Are you really a girl andrea.vermetti

I want to now so I can keep messing with kepp.  :P

LoooooL // NL
Title:
Post by: kepp on 26 May, 2005, 19:03:21

[COLOR=green]/* Open needed libraries */[/COLOR]

Lua LUA = new Lua();
LUA.OpenBaseLib();
LUA.OpenMathLib();
...
...
[COLOR=green]
/*
To register the objUser class with LUA first intialize it then
decide name for it to use in lua:
*/[/COLOR]

LUA["Sexbomb"] = objUser;

[COLOR=green]
/* The code below show you how this class can be used within LUA */[/COLOR]

Sexbomb.sPhonenumber = Sexbomb:AskPhoneNumber()
Sexbomb.sAddress = Sexbomb:AskAddress();
Sexbomb.bBiggyBoob = Sexbomb:AskBoobs();


private class objUser
{
private string mstrPhoneno = null;
private string mstrAddress = null;
private bool   mboolBigbo = false;

[COLOR=green]/* Some class properties */[/COLOR]
public string sPhonenumber
{
get {return mstrPhoneno;}
set {mstrPhoneno = value;}
}

public string sAddress
{
get {return mstrAddress;}
set {mstrAddress = value;}
}

public bool bBiggyBoob
{
get {return mboolBigbo;}
set {mboolBigbo = value;}
}

[COLOR=green]/* Class function */[/COLOR]
public string AskPhonenumber()
{
Console.WriteLine("What is your phone number??");
return Console.ReadLine();
}

public string AskAddress()
{
Console.WriteLine("What is your address?");
return Console.ReadLine();
}

public bool AskBoobs()
{
Console.WriteLine("Are they big?");
return Convert.ToBoolean(Console.ReadLine());
}
}

[COLOR=green]
/*
To get tables from LUA you should use LuaTable class.
Problem is that you cannot iterate over the table elements with this class!
I just came up with a solution to this problem which will return a lua table as
an Hashtable in C#
*/
[/COLOR]


function Hashtable GetLUATable(string Tablename)
{
Hashtable tmp = new Hashtable();
LUA["Hashtable"] = tmp; [COLOR=green]// Register out temp Hashtable to LUA[/COLOR]

[COLOR=green]// Put values in table into Hashtable[/COLOR]
LUA.DoString("for i,v in " + Tablename + " do " +
    "Hashtable:Add(i,v) " +
    "end")

LUA["Hashtable"] = null; [COLOR=green]// Converted to nil[/COLOR]
return tmp;
}

[COLOR=green]
/* Now you have a returned Hashtable, were you can iterate over both Index and Keys.
the Hashtable is accessed from System.Collections..
I havwe not tested above function but should perform the task
*/
[/COLOR]

****
GetLUATable function shall be C# function so change to C#
Title:
Post by: 6Marilyn6Manson6 on 26 May, 2005, 19:49:29
Andrea molto gnocca complimenti :D
Title: ehhh
Post by: CaSaNoVa on 26 May, 2005, 20:21:07
Sperando ke sia lei eh^_^
Title:
Post by: andrea.vermetti on 27 May, 2005, 09:08:15
Thank you everybody!!!!!!

You resolved all my trubles!!!!!


KISSES


for italian kids.....

yes i'm pretty girl from Reggio Emilia!!!!
Title: LoL
Post by: CaSaNoVa on 28 May, 2005, 03:24:27
Hi Andrea^_^

I knew you're a pretty italian girl^_^

Post me if u want speake about ptokax and scripts ;)
Title:
Post by: kepp on 28 May, 2005, 17:18:15
Yea or me...
PM me and i'll ya anything you want to know ;)