류광
unread,Dec 11, 2007, 7:04:53 AM12/11/07Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message as abuse
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to luausers-kr
C++에서 루아에 접근하는 것만 염두에 둔 간단한 라이브러리를 만들고 있습니다. 이름은 달 표면 탐사차량이라는 의미를 가진
LuaRover를 생각하고 있고요.
luausers-kr의 '파일' 란에 시험판을 올려 두었습니다.
대략 이런 식으로 사용합니다(좀 더 사용법은 test.cpp의 함수들을 보시길~)
test.lua가 이런 식이라고 할 때
global_var_int = 1234
SomeTable = {
id = 5678,
type = "some type",
pos = {
x = 100,
y = 200,
delta = {
x = 10,
y = 20
}
},
arg = "some option",
}
AnotherTable = {
id = 5679,
name = "AnotherTable",
points = {
{pos = { x = 1, y = 11} },
{pos = { x = 2, y = 22} },
{pos = { x = 3, y = 33} },
}
}
C++에서는 이런 식으로 루아에 접근합니다.
#include "lua_rover.hpp"
void f()
{
LUA_ROVER_WITH_FILE("test.lua")
{
// 전역 루아 변수 접근
int global_var_int = LG["global_var_int"];
// SomeTable 안의 필드들 접근
LUA_ROVER_WITH_TABLE("SomeTable")
{
int SomeTable_id = L["id"];
// 필드의 필드의 필드... 접근
int SomeTable_pos_delta_x =
L["pos"]["delta"]["x"];
L["pos"]["delta"]["x"] = 110; // 설정도 가능
// 일종의 상대 경로 개념
LUA_ROVER_WITH_TABLE(".pos.delta")
{
int SomeTable_pos_delta_y = L["y"];
L["x"] = 1110;
}
L["arg"] = "hello";
}
// 위의 두 방식을 결합한 것도 가능
LUA_ROVER_WITH_TABLE("SomeTable.pos.delta")
{
int SomeTable_pos_delta_y = L["y"];
}
// 배열(정수 색인) 접근도 가능
LUA_ROVER_WITH_TABLE("AnotherTable.points.2.pos")
{
int point_2_pos_x = L["x"];
}
}
}